From 94fb06bfce1f654a262e988fe224be42ffa4f8f1 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 2 Aug 2015 20:42:53 +0200 Subject: [PATCH] tcp: Fix early cancellation of timers on socket free. TCPEndpoint::Free() uses _EnterTimeWait() to start the time-wait timer for later cleanup. The latter did call _CancelConnectionTimers() unconditionally however, also cancelling a retransmit timer that was possibly still needed for the retransmission of the FIN packet. If the FIN packet got lost, the connection would be left open on the other end. --- .../kernel/network/protocols/tcp/TCPEndpoint.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp index 61f010adf8..476200681c 100644 --- a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp @@ -1138,14 +1138,16 @@ TCPEndpoint::_StartPersistTimer() void TCPEndpoint::_EnterTimeWait() { - TRACE("_EnterTimeWait()\n"); + TRACE("_EnterTimeWait()"); - _CancelConnectionTimers(); + if (fState == TIME_WAIT) { + _CancelConnectionTimers(); - if (fState == TIME_WAIT && IsLocal()) { - // we do not use TIME_WAIT state for local connections - fFlags |= FLAG_DELETE_ON_CLOSE; - return; + if (IsLocal()) { + // we do not use TIME_WAIT state for local connections + fFlags |= FLAG_DELETE_ON_CLOSE; + return; + } } _UpdateTimeWait();