Skip to content

Commit 085eb6c

Browse files
committed
Force RST on client sockets during shutdown
On OpenBSD, SO_REUSEADDR and SO_REUSEPORT are not sufficient to rebind when orphaned FIN_WAIT_2 connections hold the listen address. Set SO_LINGER with l_linger=0 on accepted client sockets before closing during shutdown so the kernel sends RST instead of FIN and releases the PCB immediately.
1 parent 3d13fa8 commit 085eb6c

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

thinproxy.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,8 +1844,20 @@ main(int argc, char *argv[])
18441844

18451845
logmsg(LOG_INFO, "shutting down");
18461846
for (i = 0; i < MAX_FDS; i++) {
1847-
if (fdmap[i] != NULL && fdtype_arr[i] == FD_CLIENT)
1848-
conn_close(fdmap[i]);
1847+
if (fdmap[i] != NULL && fdtype_arr[i] == FD_CLIENT) {
1848+
struct linger lg = { 1, 0 };
1849+
struct conn *c = fdmap[i];
1850+
/*
1851+
* Force RST on client sockets so the kernel
1852+
* releases the PCB immediately. Without this,
1853+
* connections in FIN_WAIT_2 hold the listen
1854+
* address and block bind() on restart.
1855+
*/
1856+
if (c->cfd >= 0)
1857+
(void)setsockopt(c->cfd, SOL_SOCKET,
1858+
SO_LINGER, &lg, sizeof(lg));
1859+
conn_close(c);
1860+
}
18491861
}
18501862
close(lfd);
18511863

0 commit comments

Comments
 (0)