Bug 1469117 - Make sure we reset network socket timeout epoch to 0 when timeout on a socket is turned off r=dragana
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 21 Aug 2018 14:33:52 +0000
changeset 481038 e28a399f05e8d7295955f2ce79484e64421427b5
parent 481037 038353b1a3c5f96b81fc2ff08687e4dfda250526
child 481039 f322012f5f78d689df3e5c7288e5acf25d6596f2
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersdragana
bugs1469117
milestone63.0a1
Bug 1469117 - Make sure we reset network socket timeout epoch to 0 when timeout on a socket is turned off r=dragana Differential Revision: https://phabricator.services.mozilla.com/D3880
netwerk/base/nsSocketTransportService2.cpp
netwerk/base/nsSocketTransportService2.h
--- a/netwerk/base/nsSocketTransportService2.cpp
+++ b/netwerk/base/nsSocketTransportService2.cpp
@@ -110,16 +110,24 @@ nsSocketTransportService::SocketContext:
     if (elapsed >= timeout) {
         SOCKET_LOG(("  timed out!"));
         return 0;
     }
     SOCKET_LOG(("  remains %us", PR_IntervalToSeconds(timeout - elapsed)));
     return timeout - elapsed;
 }
 
+void
+nsSocketTransportService::SocketContext::MaybeResetEpoch()
+{
+  if (mPollStartEpoch && mHandler->mPollTimeout == UINT16_MAX) {
+    mPollStartEpoch = 0;
+  }
+}
+
 //-----------------------------------------------------------------------------
 // ctor/dtor (called on the main/UI thread by the service manager)
 
 nsSocketTransportService::nsSocketTransportService()
     : mThread(nullptr)
     , mLock("nsSocketTransportService::mLock")
     , mInitialized(false)
     , mShuttingDown(false)
@@ -1271,16 +1279,18 @@ nsSocketTransportService::DoPollIteratio
             } else if (s.IsTimedOut(now)) {
 #ifdef MOZ_TASK_TRACER
 		tasktracer::AutoSourceEvent taskTracerEvent(tasktracer::SourceEventType::SocketIO);
 #endif
                 SOCKET_LOG(("socket %p timed out", s.mHandler));
                 s.DisengageTimeout();
                 s.mHandler->OnSocketReady(desc.fd, -1);
                 numberOfOnSocketReadyCalls++;
+            } else {
+                s.MaybeResetEpoch();
             }
         }
         if (mTelemetryEnabledPref) {
             Telemetry::Accumulate(
                 Telemetry::STS_NUMBER_OF_ONSOCKETREADY_CALLS,
                 numberOfOnSocketReadyCalls);
         }
 
--- a/netwerk/base/nsSocketTransportService2.h
+++ b/netwerk/base/nsSocketTransportService2.h
@@ -180,16 +180,20 @@ private:
         void EnsureTimeout(PRIntervalTime now);
         // Called after an event on a socket has been signalled to turn of the
         // timeout calculation.
         void DisengageTimeout();
         // Returns the number of intervals this socket is about to timeout in,
         // or 0 (zero) when it has already timed out.  Returns NS_SOCKET_POLL_TIMEOUT
         // when there is no timeout set on the socket.
         PRIntervalTime TimeoutIn(PRIntervalTime now) const;
+        // When a socket timeout is reset and later set again, it may happen
+        // that mPollStartEpoch is not reset in between.  We have to manually
+        // call this on every iteration over sockets to ensure the epoch reset.
+        void MaybeResetEpoch();
     };
 
     SocketContext *mActiveList;                   /* mListSize entries */
     SocketContext *mIdleList;                     /* mListSize entries */
     nsIThread     *mRawThread;
 
     uint32_t mActiveListSize;
     uint32_t mIdleListSize;