net: tcp: Fix deadlock with tcp_conn_close()
While improving thread safety of the TCP stack I've introduced a possible deadlock scenario, when calling tcp_conn_close() in tcp_in(). This function shall not be called with connection mutex locked, as it calls registered recv callback internally, which could lead to deadlock between TCP/socket mutexes. This commit moves the tcp_conn_close() back where it was originally called. I've verified that the thread safety is still solid with the test apps used originally. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
e268a6ce7d
commit
6b00b537aa
|
@ -3392,12 +3392,7 @@ out:
|
|||
goto next_state;
|
||||
}
|
||||
|
||||
/* Make sure we close the connection only once by checking connection
|
||||
* state.
|
||||
*/
|
||||
if (do_close && conn->state != TCP_UNUSED && conn->state != TCP_CLOSED) {
|
||||
tcp_conn_close(conn, close_status);
|
||||
} else if (conn->context) {
|
||||
if (conn->context) {
|
||||
/* If the conn->context is not set, then the connection was
|
||||
* already closed.
|
||||
*/
|
||||
|
@ -3423,6 +3418,13 @@ out:
|
|||
}
|
||||
}
|
||||
|
||||
/* Make sure we close the connection only once by checking connection
|
||||
* state.
|
||||
*/
|
||||
if (do_close && conn->state != TCP_UNUSED && conn->state != TCP_CLOSED) {
|
||||
tcp_conn_close(conn, close_status);
|
||||
}
|
||||
|
||||
return verdict;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue