Skip to content

Commit 97cae9c

Browse files
authored
net/tcp: close write-worker fd on async write error (#3874)
In the IO_WATCH_WRITE handler, when the stream write handler returns <0 (e.g. TLS async write fails after the 2s handshake timeout), the error branch breaks out of the switch before reaching the close(s) call that the success/pending paths hit at line 327. The fd s is delivered to the write worker via SCM_RIGHTS and is an independent copy in the worker's fd table — it must be explicitly closed on every exit path. tcpconn_release_error() signals main to close main's copy; close(s) closes the worker's copy. Without it one fd leaks per failed async write, confirmed: 7 leaked fds from 51 TLS OPTIONS (handshake timeout path) vs. 0 with the fix. Cherry-pick of bffcf00 from master. Fixes: #3711
1 parent e71bfe2 commit 97cae9c

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

net/net_tcp_proc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ inline static int handle_io(struct fd_map* fm, int idx,int event_type)
312312
"handle write, err, state: %d, att: %d",
313313
con->state, con->msg_attempts);
314314
tcpconn_release_error(con, 1,"Write error");
315+
close(s); /* we always close the socket received for writing */
315316
break;
316317
} else if (resp==1) {
317318
sh_log(con->hist, TCP_SEND2MAIN,

0 commit comments

Comments
 (0)