Bug 955888. Part 4: In chaos mode, put new sockets at a random position in the poll list. r=jduell
authorRobert O'Callahan <robert@ocallahan.org>
Mon, 03 Mar 2014 18:12:32 +1300
changeset 189857 7693a49a8210f42fbc50831f5cca4e939f895dbc
parent 189856 f741f55301efaff4d79a901189b17ef126d47d8d
child 189858 3eb91b6293587ac846e5f3d9d249820ae5754453
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs955888
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 955888. Part 4: In chaos mode, put new sockets at a random position in the poll list. r=jduell This means sockets are processed in a semi-random (but consistent) order during a poll.
netwerk/base/src/nsSocketTransportService2.cpp
--- a/netwerk/base/src/nsSocketTransportService2.cpp
+++ b/netwerk/base/src/nsSocketTransportService2.cpp
@@ -16,16 +16,18 @@
 #include "nsIPrefBranch.h"
 #include "nsServiceManagerUtils.h"
 #include "NetworkActivityMonitor.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Likely.h"
 #include "mozilla/PublicSSL.h"
+#include "mozilla/ChaosMode.h"
+#include "mozilla/PodOperations.h"
 #include "nsThreadUtils.h"
 #include "nsIFile.h"
 
 using namespace mozilla;
 using namespace mozilla::net;
 
 #if defined(PR_LOGGING)
 PRLogModuleInfo *gSocketTransportLog = nullptr;
@@ -222,22 +224,30 @@ nsSocketTransportService::AddToPollList(
     if (mActiveCount == mActiveListSize) {
         SOCKET_LOG(("  Active List size of %d met\n", mActiveCount));
         if (!GrowActiveList()) {
             NS_ERROR("too many active sockets");
             return NS_ERROR_OUT_OF_MEMORY;
         }
     }
     
-    mActiveList[mActiveCount] = *sock;
+    uint32_t newSocketIndex = mActiveCount;
+    if (ChaosMode::isActive()) {
+      newSocketIndex = ChaosMode::randomUint32LessThan(mActiveCount + 1);
+      PodMove(mActiveList + newSocketIndex + 1, mActiveList + newSocketIndex,
+              mActiveCount - newSocketIndex);
+      PodMove(mPollList + newSocketIndex + 2, mPollList + newSocketIndex + 1,
+              mActiveCount - newSocketIndex);
+    }
+    mActiveList[newSocketIndex] = *sock;
     mActiveCount++;
 
-    mPollList[mActiveCount].fd = sock->mFD;
-    mPollList[mActiveCount].in_flags = sock->mHandler->mPollFlags;
-    mPollList[mActiveCount].out_flags = 0;
+    mPollList[newSocketIndex + 1].fd = sock->mFD;
+    mPollList[newSocketIndex + 1].in_flags = sock->mHandler->mPollFlags;
+    mPollList[newSocketIndex + 1].out_flags = 0;
 
     SOCKET_LOG(("  active=%u idle=%u\n", mActiveCount, mIdleCount));
     return NS_OK;
 }
 
 void
 nsSocketTransportService::RemoveFromPollList(SocketContext *sock)
 {