commit a355874: [Fix] Disable reuseport for TCP sockets as it causes too many troubles
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Sep 11 14:42:05 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-09-11 15:40:35 +0100
URL: https://github.com/rspamd/rspamd/commit/a355874d09c6989945458d7e989718ca3c5774f3 (HEAD -> master)
[Fix] Disable reuseport for TCP sockets as it causes too many troubles
---
src/libserver/worker_util.c | 44 ++++++++++++++++++++++++++++----------------
src/rspamd.h | 1 +
2 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 40f448954..417cbc733 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -955,22 +955,32 @@ rspamd_maybe_reuseport_socket (struct rspamd_worker_listen_socket *ls)
#if defined(SO_REUSEPORT) && defined(SO_REUSEADDR) && defined(LINUX)
- nfd = rspamd_inet_address_listen (ls->addr,
- (ls->type == RSPAMD_WORKER_SOCKET_UDP ? SOCK_DGRAM : SOCK_STREAM),
- RSPAMD_INET_ADDRESS_LISTEN_ASYNC|RSPAMD_INET_ADDRESS_LISTEN_REUSEPORT,
- -1);
-
- if (nfd == -1) {
- msg_warn ("cannot create reuseport listen socket for %d: %s",
- ls->fd, strerror (errno));
- nfd = ls->fd;
+ if (ls->type == RSPAMD_WORKER_SOCKET_UDP) {
+ nfd = rspamd_inet_address_listen (ls->addr,
+ (ls->type == RSPAMD_WORKER_SOCKET_UDP ? SOCK_DGRAM : SOCK_STREAM),
+ RSPAMD_INET_ADDRESS_LISTEN_ASYNC|RSPAMD_INET_ADDRESS_LISTEN_REUSEPORT,
+ -1);
+
+ if (nfd == -1) {
+ msg_warn ("cannot create reuseport listen socket for %d: %s",
+ ls->fd, strerror (errno));
+ nfd = ls->fd;
+ }
+ else {
+ if (ls->fd != -1) {
+ close (ls->fd);
+ }
+ ls->reuseport = true;
+ ls->fd = nfd;
+ nfd = -1;
+ }
}
else {
- if (ls->fd != -1) {
- close (ls->fd);
- }
- ls->fd = nfd;
- nfd = -1;
+ /*
+ * Reuseport is broken with the current architecture, so it is easier not
+ * to use it at all
+ */
+ nfd = ls->fd;
}
#else
nfd = ls->fd;
@@ -1040,6 +1050,9 @@ rspamd_handle_child_fork (struct rspamd_worker *wrk,
g_hash_table_iter_init (&it, listen_sockets);
+ /*
+ * Close listen sockets of not our process (inherited from other forks)
+ */
while (g_hash_table_iter_next (&it, &k, &v)) {
GList *elt = (GList *)v;
GList *our = cf->listen_socks;
@@ -1159,8 +1172,7 @@ rspamd_handle_main_fork (struct rspamd_worker *wrk,
struct rspamd_worker_listen_socket *ls =
(struct rspamd_worker_listen_socket *)cur->data;
- if (!ls->is_systemd && ls->fd != -1 &&
- rspamd_inet_address_get_af (ls->addr) != AF_UNIX) {
+ if (ls->reuseport) {
close (ls->fd);
ls->fd = -1;
}
diff --git a/src/rspamd.h b/src/rspamd.h
index 2dfb512bc..470d13085 100644
--- a/src/rspamd.h
+++ b/src/rspamd.h
@@ -236,6 +236,7 @@ struct rspamd_worker_listen_socket {
gint fd;
enum rspamd_worker_socket_type type;
bool is_systemd;
+ bool reuseport;
};
typedef struct worker_s {
More information about the Commits
mailing list