mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-01 19:21:10 +00:00
http: bugfix: track closed connection
It is possible that the client disconnects before the request is handled. In those cases, evhttp_request_set_on_complete_cb is never called, which means that on shutdown the server we'll keep waiting endlessly. By adding evhttp_connection_set_closecb, libevent automatically cleans up those dead connections at latest when we shutdown, and depending on the libevent version already at the moment of remote client disconnect. In both cases, the bug is fixed. Github-Pull: #28551 Rebased-From: 68f23f57d77bc172ed39ecdd4d2d5cd5e13cf483
This commit is contained in:
parent
752a456fa8
commit
45a5fcb165
@ -266,17 +266,20 @@ std::string RequestMethodString(HTTPRequest::RequestMethod m)
|
||||
/** HTTP request callback */
|
||||
static void http_request_cb(struct evhttp_request* req, void* arg)
|
||||
{
|
||||
evhttp_connection* conn{evhttp_request_get_connection(req)};
|
||||
// Track active requests
|
||||
{
|
||||
g_requests.AddRequest(req);
|
||||
evhttp_request_set_on_complete_cb(req, [](struct evhttp_request* req, void*) {
|
||||
g_requests.RemoveRequest(req);
|
||||
}, nullptr);
|
||||
evhttp_connection_set_closecb(conn, [](evhttp_connection* conn, void* arg) {
|
||||
g_requests.RemoveConnection(conn);
|
||||
}, nullptr);
|
||||
}
|
||||
|
||||
// Disable reading to work around a libevent bug, fixed in 2.2.0.
|
||||
if (event_get_version_number() >= 0x02010600 && event_get_version_number() < 0x02020001) {
|
||||
evhttp_connection* conn = evhttp_request_get_connection(req);
|
||||
if (conn) {
|
||||
bufferevent* bev = evhttp_connection_get_bufferevent(conn);
|
||||
if (bev) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user