diff options
author | Moonchild <moonchild@palemoon.org> | 2020-12-16 07:42:37 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-12-16 07:42:37 +0000 |
commit | 810c2bf8080da2bc8ec4efb05223fea31817944b (patch) | |
tree | 1c0dfd0363791da1332e4df0d63fb11a489dd7c5 | |
parent | dabdec3b3ae9cd920e9fe75622a10ce290552941 (diff) | |
parent | 203be74ffe19ea3010e389cee32077ec6c7a173a (diff) | |
download | UXP-810c2bf8080da2bc8ec4efb05223fea31817944b.tar UXP-810c2bf8080da2bc8ec4efb05223fea31817944b.tar.gz UXP-810c2bf8080da2bc8ec4efb05223fea31817944b.tar.lz UXP-810c2bf8080da2bc8ec4efb05223fea31817944b.tar.xz UXP-810c2bf8080da2bc8ec4efb05223fea31817944b.zip |
Merge branch 'redwood' into releaseRELBASE_20201218RC_20201216
-rw-r--r-- | modules/libpref/init/all.js | 5 | ||||
-rw-r--r-- | netwerk/base/nsSocketTransportService2.cpp | 50 | ||||
-rw-r--r-- | netwerk/base/nsSocketTransportService2.h | 8 |
3 files changed, 33 insertions, 30 deletions
diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 1e60c97c5..314beac37 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1663,11 +1663,6 @@ pref("network.websocket.timeout.open", 20); // close message pref("network.websocket.timeout.close", 20); -// Setting this to true will clamp the websocket timeout value to a minimum -// regardless if there are pending events on the thread. -// This is a workaround for runaway polling, see issue #1695 -pref("network.websocket.timeout.clamped", false); - // the number of seconds of idle read activity to sustain before sending a // ping probe. 0 to disable. pref("network.websocket.timeout.ping.request", 0); diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 956332953..2a0a0868b 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -42,7 +42,6 @@ Atomic<PRThread*, Relaxed> gSocketThread; #define KEEPALIVE_PROBE_COUNT_PREF "network.tcp.keepalive.probe_count" #define SOCKET_LIMIT_TARGET 1000U #define SOCKET_LIMIT_MIN 50U -#define SOCKET_CLAMP_PREF "network.websocket.timeout.clamped" #define BLIP_INTERVAL_PREF "network.activity.blipIntervalMilliseconds" #define MAX_TIME_BETWEEN_TWO_POLLS "network.sts.max_time_for_events_between_two_polls" #define MAX_TIME_FOR_PR_CLOSE_DURING_SHUTDOWN "network.sts.max_time_for_pr_close_during_shutdown" @@ -121,8 +120,8 @@ nsSocketTransportService::nsSocketTransportService() , mKeepaliveEnabledPref(false) , mServingPendingQueue(false) , mMaxTimePerPollIter(100) - , mClampSocketTimeout(false) , mMaxTimeForPrClosePref(PR_SecondsToInterval(5)) + , mSleepPhase(false) , mProbedMaxCount(false) #if defined(XP_WIN) , mPolling(false) @@ -487,11 +486,7 @@ nsSocketTransportService::Poll(PRIntervalTime ts) mPollList[0].out_flags = 0; pollList = mPollList; pollCount = mActiveCount + 1; - pollTimeout = IsSocketTimeoutClamped() ? - PR_MillisecondsToInterval(100) : - pendingEvents ? - PR_INTERVAL_NO_WAIT : - PollTimeout(ts); + pollTimeout = pendingEvents ? PR_INTERVAL_NO_WAIT : PollTimeout(ts); } else { // no pollable event, so busy wait... @@ -500,11 +495,8 @@ nsSocketTransportService::Poll(PRIntervalTime ts) pollList = &mPollList[1]; else pollList = nullptr; - pollTimeout = IsSocketTimeoutClamped() ? - PR_MillisecondsToInterval(25) : - pendingEvents ? - PR_INTERVAL_NO_WAIT : - PR_MillisecondsToInterval(25); + pollTimeout = + pendingEvents ? PR_INTERVAL_NO_WAIT : PR_MillisecondsToInterval(25); } SOCKET_LOG((" timeout = %i milliseconds\n", @@ -563,7 +555,6 @@ nsSocketTransportService::Init() tmpPrefService->AddObserver(KEEPALIVE_RETRY_INTERVAL_PREF, this, false); tmpPrefService->AddObserver(KEEPALIVE_PROBE_COUNT_PREF, this, false); tmpPrefService->AddObserver(MAX_TIME_BETWEEN_TWO_POLLS, this, false); - tmpPrefService->AddObserver(SOCKET_CLAMP_PREF, this, false); tmpPrefService->AddObserver(MAX_TIME_FOR_PR_CLOSE_DURING_SHUTDOWN, this, false); } UpdatePrefs(); @@ -572,6 +563,8 @@ nsSocketTransportService::Init() if (obsSvc) { obsSvc->AddObserver(this, "profile-initial-state", false); obsSvc->AddObserver(this, "last-pb-context-exited", false); + obsSvc->AddObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC, true); + obsSvc->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, true); obsSvc->AddObserver(this, "xpcom-shutdown-threads", false); } @@ -638,9 +631,16 @@ nsSocketTransportService::ShutdownThread() if (obsSvc) { obsSvc->RemoveObserver(this, "profile-initial-state"); obsSvc->RemoveObserver(this, "last-pb-context-exited"); + obsSvc->RemoveObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC); + obsSvc->RemoveObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC); obsSvc->RemoveObserver(this, "xpcom-shutdown-threads"); } + if (mAfterWakeUpTimer) { + mAfterWakeUpTimer->Cancel(); + mAfterWakeUpTimer = nullptr; + } + NetworkActivityMonitor::Shutdown(); mInitialized = false; @@ -1160,13 +1160,6 @@ nsSocketTransportService::UpdatePrefs() if (NS_SUCCEEDED(rv) && maxTimePref >= 0) { mMaxTimePerPollIter = maxTimePref; } - - bool socketTimeoutClamped = false; - rv = tmpPrefService->GetBoolPref(SOCKET_CLAMP_PREF, - &socketTimeoutClamped); - if (NS_SUCCEEDED(rv)) { - mClampSocketTimeout = socketTimeoutClamped; - } int32_t maxTimeForPrClosePref; rv = tmpPrefService->GetIntPref(MAX_TIME_FOR_PR_CLOSE_DURING_SHUTDOWN, @@ -1245,6 +1238,10 @@ nsSocketTransportService::Observe(nsISupports *subject, if (!strcmp(topic, NS_TIMER_CALLBACK_TOPIC)) { nsCOMPtr<nsITimer> timer = do_QueryInterface(subject); + if (timer == mAfterWakeUpTimer) { + mAfterWakeUpTimer = nullptr; + mSleepPhase = false; + } #if defined(XP_WIN) if (timer == mPollRepairTimer) { @@ -1252,6 +1249,19 @@ nsSocketTransportService::Observe(nsISupports *subject, } #endif + } else if (!strcmp(topic, NS_WIDGET_SLEEP_OBSERVER_TOPIC)) { + mSleepPhase = true; + if (mAfterWakeUpTimer) { + mAfterWakeUpTimer->Cancel(); + mAfterWakeUpTimer = nullptr; + } + } else if (!strcmp(topic, NS_WIDGET_WAKE_OBSERVER_TOPIC)) { + if (mSleepPhase && !mAfterWakeUpTimer) { + mAfterWakeUpTimer = do_CreateInstance("@mozilla.org/timer;1"); + if (mAfterWakeUpTimer) { + mAfterWakeUpTimer->Init(this, 2000, nsITimer::TYPE_ONE_SHOT); + } + } } else if (!strcmp(topic, "xpcom-shutdown-threads")) { ShutdownThread(); } diff --git a/netwerk/base/nsSocketTransportService2.h b/netwerk/base/nsSocketTransportService2.h index 9360dd905..484dbe098 100644 --- a/netwerk/base/nsSocketTransportService2.h +++ b/netwerk/base/nsSocketTransportService2.h @@ -116,9 +116,6 @@ public: // Returns true if keepalives are enabled in prefs. bool IsKeepaliveEnabled() { return mKeepaliveEnabledPref; } - - // Returns true if socket timeout clamping is enabled in prefs. - bool IsSocketTimeoutClamped() { return mClampSocketTimeout; } PRIntervalTime MaxTimeForPrClosePref() {return mMaxTimeForPrClosePref; } protected: @@ -256,13 +253,14 @@ private: int32_t mKeepaliveProbeCount; // True if TCP keepalive is enabled globally. bool mKeepaliveEnabledPref; - // True if socket polling should be clamped. - bool mClampSocketTimeout; Atomic<bool> mServingPendingQueue; Atomic<int32_t, Relaxed> mMaxTimePerPollIter; Atomic<PRIntervalTime, Relaxed> mMaxTimeForPrClosePref; + Atomic<bool, Relaxed> mSleepPhase; + nsCOMPtr<nsITimer> mAfterWakeUpTimer; + void OnKeepaliveEnabledPrefChange(); void NotifyKeepaliveEnabledPrefChange(SocketContext *sock); |