From a6ff04d2c48be408cdcd76e5d78f4dc0a8fb9312 Mon Sep 17 00:00:00 2001 From: Oguz Bastemur Date: Fri, 31 Jan 2014 12:02:37 +0100 Subject: [PATCH] stream: start thread after assignments Changed the order of the member assignments since the thread may start before the parameters are assigned. This especially happens when the osx scheduler is very busy. --- src/unix/stream.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/unix/stream.c b/src/unix/stream.c index 0bc5fe85..c1b5e3c5 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -282,6 +282,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) { int fds[2]; int ret; int kq; + int old_fd; kq = kqueue(); if (kq == -1) { @@ -333,16 +334,20 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) { s->fake_fd = fds[0]; s->int_fd = fds[1]; - if (uv_thread_create(&s->thread, uv__stream_osx_select, stream)) - goto fatal4; - + old_fd = *fd; s->stream = stream; stream->select = s; *fd = s->fake_fd; + if (uv_thread_create(&s->thread, uv__stream_osx_select, stream)) + goto fatal4; + return 0; fatal4: + s->stream = NULL; + stream->select = NULL; + *fd = old_fd; close(s->fake_fd); close(s->int_fd); s->fake_fd = -1;