diff --git a/src/modules/transport/transport.c b/src/modules/transport/transport.c index 1bb4aa2..33a8d06 100644 --- a/src/modules/transport/transport.c +++ b/src/modules/transport/transport.c @@ -319,5 +319,11 @@ struct App_Error transport_send_frame(struct Transport_Conn *conn, } void transport_conn_close(struct Transport_Conn *conn) { - close(conn->fd); + /* shutdown() rather than close(): signals EOF to the remote end and + * unblocks the read thread without releasing the fd. The read thread + * is the sole owner of the fd and will close() it when it exits. + * Using close() here would create a race where the fd number could be + * reused by the next transport_connect() before the detached read + * thread calls its own close(), which would then close the wrong fd. */ + shutdown(conn->fd, SHUT_RDWR); }