From e82d46452e3db141d3875286cf90be0de6d724e0 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 18 May 2012 01:16:29 +0200 Subject: [PATCH] unix: fix close-before-connect bug Closing the TCP socket before the SYN/ACK handshake completed hung the event loop, the connect req didn't get unregistered. --- src/unix/stream.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/unix/stream.c b/src/unix/stream.c index f1e11733..76e25819 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -129,6 +129,13 @@ void uv__stream_destroy(uv_stream_t* stream) { assert(stream->flags & UV_CLOSED); + if (stream->connect_req) { + uv__req_unregister(stream->loop, stream->connect_req); + uv__set_artificial_error(stream->loop, UV_EINTR); + stream->connect_req->cb(stream->connect_req, -1); + stream->connect_req = NULL; + } + while (!ngx_queue_empty(&stream->write_queue)) { q = ngx_queue_head(&stream->write_queue); ngx_queue_remove(q);