Commit 004da4b
committed
Fix FIN_WAIT_2 accumulation by draining sockets before close
After shutdown(SHUT_WR) sends a FIN to the remote, tinyproxy was calling
close() without waiting for the remote FIN. The socket was orphaned in
FIN_WAIT_2 state. On Linux this is masked by tcp_fin_timeout reaping
orphaned sockets after 60s. On OpenBSD, without SO_KEEPALIVE, these
sockets persist indefinitely and accumulate until the proxy stalls.
Add close_socket() that calls shutdown(SHUT_WR), then drains the socket
with a 2-second receive timeout to allow the remote FIN to arrive before
calling close(). Use it in conn_destroy_contents() for both client and
server file descriptors, covering all exit paths from relay_connection()
including idle timeout and poll error returns.
Also add the missing shutdown(server_fd, SHUT_WR) in relay_connection()
after flushing remaining data to the upstream server, so the server
receives a proper FIN rather than relying on the implicit close().1 parent 969852c commit 004da4b
2 files changed
Lines changed: 36 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
80 | 113 | | |
81 | 114 | | |
82 | 115 | | |
83 | 116 | | |
84 | 117 | | |
85 | | - | |
86 | | - | |
87 | | - | |
| 118 | + | |
88 | 119 | | |
89 | 120 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 121 | + | |
93 | 122 | | |
94 | 123 | | |
95 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1281 | 1281 | | |
1282 | 1282 | | |
1283 | 1283 | | |
| 1284 | + | |
1284 | 1285 | | |
1285 | 1286 | | |
1286 | 1287 | | |
| |||
0 commit comments