net: tcp: Fix possible deadlock in tcp_conn_unref()

Unlock tcp_lock when calling the recv_cb. In case when
a connection is being closed from both the tcp stack
and the application, a race condition can happen resulting
in locking each other out on tcp_lock and socket lock.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
This commit is contained in:
Daniel Nejezchleb 2022-02-07 10:13:04 +01:00 committed by Anas Nashif
commit e7489d8de7

View file

@ -403,8 +403,10 @@ static int tcp_conn_unref(struct tcp *conn)
}
if (conn->context->recv_cb) {
k_mutex_unlock(&tcp_lock);
conn->context->recv_cb(conn->context, NULL, NULL, NULL,
-ECONNRESET, conn->recv_user_data);
k_mutex_lock(&tcp_lock, K_FOREVER);
}
conn->context->tcp = NULL;