Bug 1055316 - Fix unix socket connect backoff scheme such that it will actually backoff. r=tzimmermann
authorAndrew Osmond <aosmond@mozilla.com>
Mon, 18 Aug 2014 15:53:00 -0400
changeset 214903 9de0463fb1c721a3423a5275ed60db8b3a16f802
parent 214902 ac8948dcc1efab68f39b19e6ebc15d5085a2e7e1
child 214904 8d72d8f5f247cd3e0198f08a1ab67118635f85f2
push idunknown
push userunknown
push dateunknown
reviewerstzimmermann
bugs1055316
milestone34.0a1
Bug 1055316 - Fix unix socket connect backoff scheme such that it will actually backoff. r=tzimmermann
ipc/unixsocket/SocketBase.cpp
--- a/ipc/unixsocket/SocketBase.cpp
+++ b/ipc/unixsocket/SocketBase.cpp
@@ -71,37 +71,39 @@ SocketConsumerBase::NotifySuccess()
 
 void
 SocketConsumerBase::NotifyError()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   mConnectionStatus = SOCKET_DISCONNECTED;
   mConnectDelayMs = CalculateConnectDelayMs();
+  mConnectTimestamp = 0;
   OnConnectError();
 }
 
 void
 SocketConsumerBase::NotifyDisconnect()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   mConnectionStatus = SOCKET_DISCONNECTED;
   mConnectDelayMs = CalculateConnectDelayMs();
+  mConnectTimestamp = 0;
   OnDisconnect();
 }
 
 uint32_t
 SocketConsumerBase::CalculateConnectDelayMs() const
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   uint32_t connectDelayMs = mConnectDelayMs;
 
-  if ((PR_IntervalNow()-mConnectTimestamp) > connectDelayMs) {
+  if (mConnectTimestamp && (PR_IntervalNow()-mConnectTimestamp) > connectDelayMs) {
     // reset delay if connection has been opened for a while, or...
     connectDelayMs = 0;
   } else if (!connectDelayMs) {
     // ...start with a delay of ~1 sec, or...
     connectDelayMs = 1<<10;
   } else if (connectDelayMs < (1<<16)) {
     // ...otherwise increase delay by a factor of 2
     connectDelayMs <<= 1;