osrm-backend/server
Daniel J. Hofmann 3279cbac24 Extend compressed output lifetime till the async write function finishes.
This extends the compressed output vector's lifetime, as we issue an
asynchronous write operation that only receives a non-owning buffer to
the compressed data.

When the compressed output vector then goes out of scope, its destructor
is called and the data gets (potentially) destroyed. If the asynchronous
write happens afterwards, it's accessing data that is no longer there.

This is the reason for race conditions --- well, for undefined behavior
in general, but it manifests in the routed _sometimes_ not responding at
all.

The fix works like this: keep the compressed output associated with a
connection. Connections inherit from `std::enable_shared_from_this` and
issues a `shared_from_this()` call, passing a `std::shared_ptr` to the
asynchronous write function, thus extending their lifetime.

Connecitons thus manage their lifetime by themselves, extending it when
needed (and of course via the `std::shared_pointers` pointing to it).

Buffer's non owning property, from the `async_write` documentation:

> One or more buffers containing the data to be written. Although
> the buffers object may be copied as necessary, ownership of the
> underlying memory blocks is retained by the caller, which must
> guarantee that they remain valid until the handler is called.

Reference:

- http://www.boost.org/doc/libs/1_59_0/doc/html/boost_asio/reference/async_write/overload1.html
2015-09-16 02:06:58 +02:00
..
data_structures Candidate query for match is now only depending on gps_precision 2015-09-03 17:02:33 +02:00
http Modernize the code base to C++11 standards and beyond. 2015-08-18 12:56:34 +02:00
api_grammar.hpp remove possibility to choose algorithm but only use brute force and farthest insertion 2015-09-01 15:20:34 +02:00
connection.cpp Extend compressed output lifetime till the async write function finishes. 2015-09-16 02:06:58 +02:00
connection.hpp Extend compressed output lifetime till the async write function finishes. 2015-09-16 02:06:58 +02:00
request_handler.cpp fix code-format regression 2015-02-24 09:08:59 +01:00
request_handler.hpp change copyright line from personal names to project 2015-02-19 09:19:51 +01:00
request_parser.cpp Content Type validation added 2015-06-01 09:42:22 +02:00
request_parser.hpp Handle POST request when spanning multiple packets 2015-05-31 21:34:38 +02:00
server.hpp change copyright line from personal names to project 2015-02-19 09:19:51 +01:00