| 563 | } |
| 564 | |
| 565 | void HTTPRequest::startDetectClientClose() { |
| 566 | LogPrint("http-poll", "start detect http connection close\n"); |
| 567 | // will need to call evhttp_send_reply_end to clean this up |
| 568 | auto conn = evhttp_request_get_connection(req); |
| 569 | |
| 570 | // evhttp_connection_set_closecb does not reliably detect client connection close unless we write to it. |
| 571 | // |
| 572 | // This problem is supposedly resolved in 2.1.8. See: https://github.com/libevent/libevent/issues/78 |
| 573 | // |
| 574 | // But we should just write to the socket to test liveness. This is useful for long-poll RPC calls to see |
| 575 | // if they should terminate the request early. |
| 576 | // |
| 577 | // More weirdness: if process received SIGTERM, the http event loop (in HTTPThread) returns prematurely with 1. |
| 578 | // In which case evhttp_send_reply_end doesn't seem to get called, and evhttp_connection_set_closecb is |
| 579 | // not called. BUT when the event base is freed, this callback IS called, and HTTPRequest is already freed. |
| 580 | // |
| 581 | // So, waitClientClose and startDetectClientClose should just not do anything if RPC is shutting down. |
| 582 | evhttp_connection_set_closecb(conn, [](struct evhttp_connection *conn, void *data) { |
| 583 | LogPrint("http-poll", "http connection close detected\n"); |
| 584 | |
| 585 | if (IsRPCRunning()) { |
| 586 | auto req = (HTTPRequest*) data; |
| 587 | req->setConnClosed(); |
| 588 | } |
| 589 | }, (void *) this); |
| 590 | } |
| 591 | |
| 592 | void HTTPRequest::setConnClosed() { |
| 593 | std::lock_guard<std::mutex> lock(cs); |
nothing calls this directly
no test coverage detected