Skip to content

Commit

Permalink
Close sockets before trying to kill thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj committed Mar 3, 2025
1 parent 5d4655b commit 932c2f8
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/platform/posix/tcp_ip_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,12 @@ static void TcpIpChannel_free(NetworkChannel *untyped_self) {
TCP_IP_CHANNEL_DEBUG("Free");
self->terminate = true;

self->super.close_connection((NetworkChannel *)self);

if (self->worker_thread != 0) {
int err = 0;
TCP_IP_CHANNEL_DEBUG("Stopping worker thread");

ssize_t bytes_written = write(self->send_failed_event_fds[1], "X", 1);
if (bytes_written == -1) {
TCP_IP_CHANNEL_ERR("Failed to stop worker thread through the send_failed_event. errno=%d", errno);
}

err = pthread_cancel(self->worker_thread);

if (err != 0) {
Expand All @@ -543,7 +540,6 @@ static void TcpIpChannel_free(NetworkChannel *untyped_self) {
TCP_IP_CHANNEL_ERR("Error destroying pthread attr %d", err);
}
}
self->super.close_connection((NetworkChannel *)self);
pthread_mutex_destroy(&self->mutex);
}

Expand Down

0 comments on commit 932c2f8

Please sign in to comment.