commit da8389e8f2950cbb3727332844ade33c5e51d329
parent ece353863b449abbc1026af2946bfd3745118c63
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 30 Aug 2025 21:56:07 +0200
clean up disconnected clients on next connect instead of just on shutdown (#10313)
Diffstat:
1 file changed, 41 insertions(+), 8 deletions(-)
diff --git a/src/util/secmod_common.c b/src/util/secmod_common.c
@@ -219,11 +219,15 @@ TES_wake_clients (void)
client = client->next)
{
#ifdef __linux__
+ if (-1 == client->esock)
+ continue;
GNUNET_assert (sizeof (num) ==
write (client->esock,
&num,
sizeof (num)));
#else
+ if (-1 == client->esock_in)
+ continue;
GNUNET_assert (sizeof (num) ==
write (client->esock_in,
&num,
@@ -398,6 +402,17 @@ sign_worker (void *cls)
break;
}
}
+ GNUNET_break (0 == close (client->csock));
+ client->csock = -1;
+#ifdef __linux__
+ GNUNET_break (0 == close (client->esock));
+ client->esock = -1;
+#else
+ GNUNET_break (0 == close (client->esock_in));
+ client->esock_in = -1;
+ GNUNET_break (0 == close (client->esock_out));
+ client->esock_out = -1;
+#endif
return NULL;
}
@@ -429,8 +444,15 @@ listen_job (void *cls)
&sa_len);
if (-1 == s)
{
+ bool st = ( (ENFILE == errno) ||
+ (EMFILE == errno) );
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"accept");
+ if (st)
+ {
+ GNUNET_SCHEDULER_cancel (listen_task);
+ listen_task = NULL;
+ }
return;
}
#ifdef __linux__
@@ -454,6 +476,7 @@ listen_job (void *cls)
#endif
{
struct TES_Client *client;
+ struct TES_Client *nxt;
client = GNUNET_new (struct TES_Client);
client->cb = *cb;
@@ -465,6 +488,24 @@ listen_job (void *cls)
client->esock_out = e[0];
#endif
GNUNET_assert (0 == pthread_mutex_lock (&TES_clients_lock));
+ for (struct TES_Client *pos = TES_clients_head;
+ NULL != pos;
+ pos = nxt)
+ {
+ nxt = pos->next;
+ if (-1 == pos->csock)
+ {
+ void *rval;
+
+ GNUNET_CONTAINER_DLL_remove (TES_clients_head,
+ TES_clients_tail,
+ pos);
+ GNUNET_break (0 ==
+ pthread_join (pos->worker,
+ &rval));
+ GNUNET_free (pos);
+ }
+ }
GNUNET_CONTAINER_DLL_insert (TES_clients_head,
TES_clients_tail,
client);
@@ -531,7 +572,6 @@ TES_listen_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
&TES_smpub.eddsa_pub);
}
-
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
section,
@@ -596,13 +636,6 @@ TES_listen_stop (void)
GNUNET_break (0 ==
pthread_join (client->worker,
&rval));
- GNUNET_break (0 == close (client->csock));
-#ifdef __linux__
- GNUNET_break (0 == close (client->esock));
-#else
- GNUNET_break (0 == close (client->esock_in));
- GNUNET_break (0 == close (client->esock_out));
-#endif
GNUNET_free (client);
}
GNUNET_assert (0 == pthread_mutex_unlock (&TES_clients_lock));