diff --git a/src/init.c b/src/init.c index e9a317eefb2f8..6f3803460f7e8 100644 --- a/src/init.c +++ b/src/init.c @@ -428,6 +428,10 @@ void *init_stdio_handle(uv_file fd,int readable) // On windows however, libuv objects remember streams by their HANDLE, so this is // unnessecary. fd = dup(fd); +#else + // Duplicate the file descritor so libuv can later close it without having to worry + // about needing to keep its handle open + fd = _dup(fd); #endif //printf("%d: %d -- %d\n", fd, type, 0); switch(type) { diff --git a/src/jl_uv.c b/src/jl_uv.c index 52dcd50c9ad77..995ebb9e9ed22 100644 --- a/src/jl_uv.c +++ b/src/jl_uv.c @@ -148,7 +148,7 @@ DLLEXPORT void jl_uv_shutdownCallback(uv_shutdown_t* req, int status) * in the shutdown request (in that case we call uv_close, thus cancelling this) * request. */ - if (status != UV__ECANCELED) { + if (status != UV__ECANCELED && !uv_is_closing((uv_handle_t*)req->handle)) { uv_close((uv_handle_t*) req->handle, &jl_uv_closeHandle); } free(req); @@ -299,7 +299,7 @@ DLLEXPORT void jl_close_uv(uv_handle_t *handle) fd->file = -1; } } - else { + else if (!uv_is_closing((uv_handle_t*)handle)) { uv_close(handle,&jl_uv_closeHandle); } }