Skip to content

Commit

Permalink
Fix incorrect server connection reference conter
Browse files Browse the repository at this point in the history
We should put server connection reference counter
before call it's destructor

Closes #1910
  • Loading branch information
EvgeniiMekhanik committed Jul 14, 2023
1 parent a467fc6 commit d50b32d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions fw/websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,17 @@ tfw_ws_srv_new_steal_sk(TfwSrvConn *srv_conn)
*/
conn->sk->sk_user_data = conn;

/* Connection destructor does failover for server connections */
srv_conn->sk = NULL;
if (srv_conn->destructor)
srv_conn->destructor(srv_conn);
/*
* Connection destructor does failover for server connections.
* There is no problem here that we have srv_conn reference counter
* equal to zero, because srv->conn->sk is NULL. If connection will
* be reestablished `tfw_sock_srv_connect_try` will be called and
* we set new sk and not 0 reference counter to this connection,
* ohterwise ss_close finished imidiatly and we never drop this
* connection again.
*/
tfw_connection_put((TfwConn *)srv_conn);

return conn;
}
Expand Down

0 comments on commit d50b32d

Please sign in to comment.