FirebirdSQL / firebird

Firebird server, client and tools
https://firebirdsql.org
1.26k stars 217 forks source link

Ensure the standalone CS listener on Linux uses the SO_REUSEADDR socket option #8181

Closed dyemanov closed 4 months ago

dyemanov commented 4 months ago

In recent FB versions Classic on Linux uses its native listener instead of xinetd/systemd. While we usually don't expect it to crash, it's still possible. However, often it cannot continue listening the port immediately after restart because the port is still in the FIN_WAIT state and the SO_REUSEADDR socket option is not used by the standalone Classic listener, thus causing "address already in use" errors during startup. This patch ensures that any kind of listeners (SS/SC using SRVR_multi_thread and CS standalone server) uses the SO_REUSEADDR option to avoid the issue.

Maybe (after this patch) we should also cleanup the retry loop for INET_ADDR_IN_USE used later in this function, as it's likely to be pointless, but I leave it for another day.