From: Azat Khuzhin Date: Sun, 15 Nov 2015 21:55:30 +0000 (+0300) Subject: http: install timeout for read too during connect for ssl X-Git-Tag: release-2.1.6-beta~90^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=040000d7a779c3f153f46649368c6951708d9e28;p=libevent http: install timeout for read too during connect for ssl Since during ssl handshake we can read too, and if something nasty will happens during this handshake (because of too many events in the loop of something like this) we can wait forever since there is no read timeout: (gdb) p *$2.task.connection.bufev $11 = { ... be_ops = 0x7f78c2864b00 , ev_read = { ... ev_ = { ev_io = { ... ev_timeout = { tv_sec = 0, tv_usec = 0 } }, ev_signal = { ... } }, ev_events = 82, ev_res = 2, ev_timeout = { tv_sec = 10889976, tv_usec = 418753 } }, ev_write = { ... ev_ = { ev_io = { ... ev_timeout = { tv_sec = 20, tv_usec = 0 } }, ev_signal = { ... } }, ev_events = 84, ev_res = 4, ev_timeout = { tv_sec = 10889977, tv_usec = 598753 } }, ... errorcb = 0x7f78c287de70 , ... timeout_read = { tv_sec = 0, tv_usec = 0 }, timeout_write = { tv_sec = 20, tv_usec = 0 }, enabled = 4 } (gdb) bt #0 0x00007f78c17c3633 in __epoll_wait_nocancel () at syscall-template.S:81 #1 0x00007f78c2aaf508 in epoll_dispatch (base=0x18f76d0, tv=) at epoll.c:463 ... Found-with: massive crawling Tested-with: massive crawling --- diff --git a/http.c b/http.c index 75b902dc..b879132a 100644 --- a/http.c +++ b/http.c @@ -2471,9 +2471,9 @@ evhttp_connection_connect_(struct evhttp_connection *evcon) evcon); if (!evutil_timerisset(&evcon->timeout)) { const struct timeval conn_tv = { HTTP_CONNECT_TIMEOUT, 0 }; - bufferevent_set_timeouts(evcon->bufev, NULL, &conn_tv); + bufferevent_set_timeouts(evcon->bufev, &conn_tv, &conn_tv); } else { - bufferevent_set_timeouts(evcon->bufev, NULL, &evcon->timeout); + bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); } /* make sure that we get a write callback */ bufferevent_enable(evcon->bufev, EV_WRITE);