fix(server): check kill_recv in accept() loop to prevent hang on stop

If server_stop() is called before any client connects, the accept()
loop would spin forever since kill_recv was never checked, causing
pthread_join() to block indefinitely.

Add kill_recv check at the top of the accept() polling loop so the
thread can exit cleanly when server_stop() is called during the
pre-connection phase.
This commit is contained in:
2026-03-12 11:51:56 +03:00
parent 1c36292b1f
commit 5bb776c432

View File

@@ -436,8 +436,12 @@ _start_server_cb(void* userdata)
int c = sizeof(struct sockaddr_in);
int client_socket;
errno = 0;
// DEBUG removed
while ((client_socket = accept(listen_socket, (struct sockaddr *)&client_addr, (socklen_t*)&c)) == -1) {
if (kill_recv) {
log_println(STBBR_LOGINFO, "Accept loop interrupted by stop request");
_shutdown();
return NULL;
}
if (errno != EAGAIN && errno != EWOULDBLOCK) {
log_println(STBBR_LOGERROR, "Accept failed: %s", strerror(errno));
return NULL;