Skip to content

Commit 7e57e30

Browse files
committed
Add SO_REUSEPORT to allow bind with orphaned FIN_WAIT_2 sockets
On OpenBSD, SO_REUSEADDR is not sufficient to bind when orphaned FIN_WAIT_2 connections exist on the same local address:port (e.g. after stopping a previous proxy). SO_REUSEPORT allows the bind to succeed.
1 parent 8f2c710 commit 7e57e30

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

thinproxy.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,10 @@ setup_listener(const char *addr, const char *port)
16561656
on = 1;
16571657
(void)setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
16581658
&on, sizeof(on));
1659+
#ifdef SO_REUSEPORT
1660+
(void)setsockopt(fd, SOL_SOCKET, SO_REUSEPORT,
1661+
&on, sizeof(on));
1662+
#endif
16591663
if (bind(fd, r->ai_addr, r->ai_addrlen) == -1) {
16601664
err = errno;
16611665
close(fd);

0 commit comments

Comments
 (0)