Skip to content

Commit 2098773

Browse files
committed
Revert "unix,tcp: avoid marking server sockets connected"
Reverted for breaking Node.js in rather spectacular fashion. The bug is arguably on the Node.js side. It looks like Node.js starts reading before the socket is actually connected to something. Until that is fixed downstream, let's revert the change. This reverts commit fd04939. Fixes: #1716 Fixes: nodejs/node#18225 PR-URL: #1717 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
1 parent 1366e74 commit 2098773

4 files changed

Lines changed: 5 additions & 53 deletions

File tree

src/unix/stream.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,9 +1411,6 @@ int uv_write2(uv_write_t* req,
14111411
if (uv__stream_fd(stream) < 0)
14121412
return -EBADF;
14131413

1414-
if (!(stream->flags & UV_STREAM_WRITABLE))
1415-
return -EPIPE;
1416-
14171414
if (send_handle) {
14181415
if (stream->type != UV_NAMED_PIPE || !((uv_pipe_t*)stream)->ipc)
14191416
return -EINVAL;
@@ -1565,9 +1562,6 @@ int uv_read_start(uv_stream_t* stream,
15651562
if (stream->flags & UV_CLOSING)
15661563
return -EINVAL;
15671564

1568-
if (!(stream->flags & UV_STREAM_READABLE))
1569-
return -ENOTCONN;
1570-
15711565
/* The UV_STREAM_READING flag is irrelevant of the state of the tcp - it just
15721566
* expresses the desired state of the user.
15731567
*/

src/unix/tcp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ int uv__tcp_bind(uv_tcp_t* tcp,
158158
if ((flags & UV_TCP_IPV6ONLY) && addr->sa_family != AF_INET6)
159159
return -EINVAL;
160160

161-
err = maybe_new_socket(tcp, addr->sa_family, 0);
161+
err = maybe_new_socket(tcp,
162+
addr->sa_family,
163+
UV_STREAM_READABLE | UV_STREAM_WRITABLE);
162164
if (err)
163165
return err;
164166

@@ -333,14 +335,14 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
333335
if (single_accept)
334336
tcp->flags |= UV_TCP_SINGLE_ACCEPT;
335337

336-
flags = 0;
338+
flags = UV_STREAM_READABLE;
337339
#if defined(__MVS__)
338340
/* on zOS the listen call does not bind automatically
339341
if the socket is unbound. Hence the manual binding to
340342
an arbitrary port is required to be done manually
341343
*/
342344
flags |= UV_HANDLE_BOUND;
343-
#endif
345+
#endif
344346
err = maybe_new_socket(tcp, AF_INET, flags);
345347
if (err)
346348
return err;

test/test-list.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ TEST_DECLARE (tcp_bind_error_fault)
9494
TEST_DECLARE (tcp_bind_error_inval)
9595
TEST_DECLARE (tcp_bind_localhost_ok)
9696
TEST_DECLARE (tcp_bind_invalid_flags)
97-
TEST_DECLARE (tcp_bind_writable_flags)
9897
TEST_DECLARE (tcp_listen_without_bind)
9998
TEST_DECLARE (tcp_connect_error_fault)
10099
TEST_DECLARE (tcp_connect_timeout)
@@ -535,7 +534,6 @@ TASK_LIST_START
535534
TEST_ENTRY (tcp_bind_error_inval)
536535
TEST_ENTRY (tcp_bind_localhost_ok)
537536
TEST_ENTRY (tcp_bind_invalid_flags)
538-
TEST_ENTRY (tcp_bind_writable_flags)
539537
TEST_ENTRY (tcp_listen_without_bind)
540538
TEST_ENTRY (tcp_connect_error_fault)
541539
TEST_ENTRY (tcp_connect_timeout)

test/test-tcp-bind-error.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -214,45 +214,3 @@ TEST_IMPL(tcp_listen_without_bind) {
214214
MAKE_VALGRIND_HAPPY();
215215
return 0;
216216
}
217-
218-
219-
TEST_IMPL(tcp_bind_writable_flags) {
220-
struct sockaddr_in addr;
221-
uv_tcp_t server;
222-
uv_buf_t buf;
223-
uv_write_t write_req;
224-
uv_shutdown_t shutdown_req;
225-
int r;
226-
227-
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
228-
r = uv_tcp_init(uv_default_loop(), &server);
229-
ASSERT(r == 0);
230-
r = uv_tcp_bind(&server, (const struct sockaddr*) &addr, 0);
231-
ASSERT(r == 0);
232-
r = uv_listen((uv_stream_t*)&server, 128, NULL);
233-
ASSERT(r == 0);
234-
235-
ASSERT(0 == uv_is_writable((uv_stream_t*) &server));
236-
ASSERT(0 == uv_is_readable((uv_stream_t*) &server));
237-
238-
buf = uv_buf_init("PING", 4);
239-
r = uv_write(&write_req, (uv_stream_t*) &server, &buf, 1, NULL);
240-
ASSERT(r == UV_EPIPE);
241-
r = uv_shutdown(&shutdown_req, (uv_stream_t*) &server, NULL);
242-
#ifdef _WIN32
243-
ASSERT(r == UV_EPIPE);
244-
#else
245-
ASSERT(r == UV_ENOTCONN);
246-
#endif
247-
r = uv_read_start((uv_stream_t*) &server, NULL, NULL);
248-
ASSERT(r == UV_ENOTCONN);
249-
250-
uv_close((uv_handle_t*)&server, close_cb);
251-
252-
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
253-
254-
ASSERT(close_cb_called == 1);
255-
256-
MAKE_VALGRIND_HAPPY();
257-
return 0;
258-
}

0 commit comments

Comments
 (0)