diff --git a/src/unix/pipe.c b/src/unix/pipe.c index fb40e962..d88ac392 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -81,22 +81,10 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { uv_strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path)); saddr.sun_family = AF_UNIX; - if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) { - /* On EADDRINUSE: - * - * We hold the file lock so there is no other process listening - * on the socket. Ergo, it's stale - remove it. - * - * This assumes that the other process uses locking too - * but that's a good enough assumption for now. - */ - if (errno != EADDRINUSE - || unlink(pipe_fname) == -1 - || bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) { - /* Convert ENOENT to EACCES for compatibility with Windows. */ - uv__set_sys_error(handle->loop, (errno == ENOENT) ? EACCES : errno); - goto out; - } + if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) { + /* Convert ENOENT to EACCES for compatibility with Windows. */ + uv__set_sys_error(handle->loop, (errno == ENOENT) ? EACCES : errno); + goto out; } bound = 1; diff --git a/test/test-pipe-bind-error.c b/test/test-pipe-bind-error.c index b84d20f1..4e73b639 100644 --- a/test/test-pipe-bind-error.c +++ b/test/test-pipe-bind-error.c @@ -27,8 +27,10 @@ #ifdef _WIN32 # define BAD_PIPENAME "bad-pipe" +# define UNLINK_PIPE(name) #else # define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there" +# define UNLINK_PIPE(name) remove(name) #endif @@ -45,6 +47,8 @@ TEST_IMPL(pipe_bind_error_addrinuse) { uv_pipe_t server1, server2; int r; + UNLINK_PIPE(TEST_PIPENAME); + r = uv_pipe_init(uv_default_loop(), &server1, 0); ASSERT(r == 0); r = uv_pipe_bind(&server1, TEST_PIPENAME);