[Midnightbsd-cvs] src [8793] trunk/sys/netinet/tcp_input.c: This small change takes care of a race condition that can occur when both sides close at the same time.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 25 23:19:44 EDT 2016


Revision: 8793
          http://svnweb.midnightbsd.org/src/?rev=8793
Author:   laffer1
Date:     2016-09-25 23:19:43 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
This small change takes care of a race condition that can occur when both sides close at the same time.

Modified Paths:
--------------
    trunk/sys/netinet/tcp_input.c

Modified: trunk/sys/netinet/tcp_input.c
===================================================================
--- trunk/sys/netinet/tcp_input.c	2016-09-26 03:19:15 UTC (rev 8792)
+++ trunk/sys/netinet/tcp_input.c	2016-09-26 03:19:43 UTC (rev 8793)
@@ -2448,6 +2448,16 @@
 						}
 					} else
 						tp->snd_cwnd += tp->t_maxseg;
+					if ((thflags & TH_FIN) &&
+					    (TCPS_HAVERCVDFIN(tp->t_state) == 0)) {
+						/* 
+						 * If its a fin we need to process
+						 * it to avoid a race where both
+						 * sides enter FIN-WAIT and send FIN|ACK
+						 * at the same time.
+						 */
+						break;
+					}
 					(void) tcp_output(tp);
 					goto drop;
 				} else if (tp->t_dupacks == tcprexmtthresh) {
@@ -2487,6 +2497,16 @@
 					}
 					tp->snd_nxt = th->th_ack;
 					tp->snd_cwnd = tp->t_maxseg;
+					if ((thflags & TH_FIN) &&
+					    (TCPS_HAVERCVDFIN(tp->t_state) == 0)) {
+						/* 
+						 * If its a fin we need to process
+						 * it to avoid a race where both
+						 * sides enter FIN-WAIT and send FIN|ACK
+						 * at the same time.
+						 */
+						break;
+					}
 					(void) tcp_output(tp);
 					KASSERT(tp->snd_limited <= 2,
 					    ("%s: tp->snd_limited too big",
@@ -2513,6 +2533,16 @@
 					    (tp->snd_nxt - tp->snd_una) +
 					    (tp->t_dupacks - tp->snd_limited) *
 					    tp->t_maxseg;
+					if ((thflags & TH_FIN) &&
+					    (TCPS_HAVERCVDFIN(tp->t_state) == 0)) {
+						/* 
+						 * If its a fin we need to process
+						 * it to avoid a race where both
+						 * sides enter FIN-WAIT and send FIN|ACK
+						 * at the same time.
+						 */
+						break;
+					}
 					(void) tcp_output(tp);
 					sent = tp->snd_max - oldsndmax;
 					if (sent > tp->t_maxseg) {



More information about the Midnightbsd-cvs mailing list