Skip to content

Commit

Permalink
TCP engine: Fix a race condition related to con lifetime management
Browse files Browse the repository at this point in the history
Connections which received a read event concurrently with their
expiration time could trigger an indefinitely long, CPU wasteful, rapid
succession of back-forth passing of the connection object between TCP Main
and a TCP worker process.

The fix involves adding a TCP connection lifetime update in the TCP worker
just after receiving the connection object from TCP Main (this is correct
- there is some pending data, the connection is non-idle), before the
expiration check is done.

Thanks to Bogdan for helping with troubleshooting

(cherry picked from commit 9918171)
  • Loading branch information
liviuchircu committed Jul 3, 2017
1 parent 7d30b9c commit 9ede589
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions net/net_tcp_proc.c
Expand Up @@ -168,6 +168,8 @@ inline static int handle_io(struct fd_map* fm, int idx,int event_type)
* handle_io might decide to del. the new connection =>
* must be in the list */
tcpconn_listadd(tcp_conn_lst, con, c_next, c_prev);
/* pending event on a connection -> prevent premature expiry */
tcp_conn_set_lifetime(con, tcp_con_lifetime);
con->timeout = con->lifetime;
if (reactor_add_reader( s, F_TCPCONN, RCT_PRIO_NET, con )<0) {
LM_CRIT("failed to add new socket to the fd list\n");
Expand Down

0 comments on commit 9ede589

Please sign in to comment.