Resolver::add_callback invoked the callback synchronously on the
calling thread when resolution was already completed. Since Request
objects are commonly created and sent from application threads while
the io_context runs on a dedicated io thread, the whole continuation
(Request::send -> Request::connect -> Connection::async_connect ->
asio::async_connect start_connect_op) then executed on the caller's
thread, mutating asio reactor state (kqueue/epoll per-descriptor op
queues) concurrently with the io thread. This data race corrupts the
heap and was observed crashing with SIGSEGV/EXC_BAD_ACCESS inside
asio start_connect_op, both from the io thread and from the
application main thread (e.g. a name lookup reusing a shared,
already-completed Resolver), on macOS.
Fix by always posting completed-resolution callbacks to the
resolver's executor, so the connect chain consistently runs on the
io_context thread regardless of the caller.
Also make the Connection::async_connect completion handler hold a
weak_ptr to the Connection instead of capturing raw `this` and a
reference to the underlying socket, matching the existing
async_handshake pattern, so a Connection destroyed while a connect
operation is in flight (e.g. after a request timeout) can no longer
be written to after free.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
For routes such as /api/auth/directory/search, when searching for names such as
"Léo", jams would not respond to the request
since the URL contained invalid characters defined in RFC3986. `url_encode`
turns such characters into their equivalent escaped characters.
When switching between two network interfaces, local address will
change but not the public ip. This generally cause the client to
not correctly updates its candidates.
In this patch, we inject in the proxy client the local candidates
and use it to check if the network changed.
In the previous version, the timeout for the connection could be
set only after async_connect while the request is sending.
This means if async_connect is slow (it can happen as if there is
an ipv6 endpoint, it can try to resolve it during dozens of seconds
before falling back on ipv4).
In this patch, it moves the timeout callback in the request. This
callback will be set just before async_connect, to be sure that we
are using the callback while connecting.
- pre-decode certs from DER->PEM and store them so http connections
can add them the ssl context x509 store
- fixes the windows build by adding the crypto/x509 header