evhttp can detect when a connection gets closed by the peer, but only for outgoing connections. For incoming connections, evhttp will only notice that the connection has gone down when it'll try to send a reply.
This is a problem for protocols implementing a push mechanism with HTTP requests that the server won't reply to until some event happens. In this context, the server needs to be notified when the connection goes down so as to perform cleanup tasks.
The proposed patch extends the detection mechanism used for outgoing connections and comes on top of my previous evhttp patch (submitted as #2862554) adding a "connection failed" callback to evhttp_request.
Like my previous patch, this is tested and included in my forked-daapd project. Works just fine.
Proposed patch
View and moderate all "patches Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Please use https://github.com/libevent/libevent/pulls"
libevent-2.0 series also has this issue.
Now it works fine with following patch(passed with make verify)
--- http.c.old 2011-08-17 12:31:19.000000000 +0800
+++ http.c 2011-08-17 12:32:20.000000000 +0800
@@ -810,6 +810,10 @@
* connection so that we can reply to it.
*/
evcon->state = EVCON_WRITING;
+ /*
+ * enable READ event for detect connection error
+ */
+ bufferevent_enable(req->evcon->bufev, EV_READ);
}
/* notify the user of the request */
moving to the patches tracker where it belongs