diff --git a/src/ssb.c b/src/ssb.c index 206cdfa7..2d892752 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -2719,7 +2719,8 @@ static void _tf_ssb_connection_finalizer(JSRuntime* runtime, JSValue value) static void _tf_ssb_connection_process_message_async(uv_async_t* async) { tf_ssb_connection_t* connection = async->data; - if (!connection->is_closing && _tf_ssb_connection_box_stream_recv(connection)) + /* The receive may initiate a close, so this order is important. */ + if (_tf_ssb_connection_box_stream_recv(connection) && !connection->is_closing) { uv_async_send(&connection->async); }