From 854aecd889625e479826ccf7dbf825d46a9adf71 Mon Sep 17 00:00:00 2001 From: Dragana Damjanovic Date: Fri, 15 Jan 2016 08:21:00 +0100 Subject: [PATCH] Bug 1239961 - Minimize amount of PR_Poll and PR_Read calls during shutdown. r=mcmanus --- netwerk/base/nsSocketTransportService2.cpp | 12 +++++++++++- netwerk/protocol/http/nsHttpConnection.cpp | 5 +++-- netwerk/protocol/http/nsHttpConnection.h | 2 +- netwerk/protocol/http/nsHttpConnectionMgr.cpp | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 491c9a0c5db8..95a6f8fa2ad1 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -8,6 +8,7 @@ #include "nsSocketTransport2.h" #include "NetworkActivityMonitor.h" #include "mozilla/Preferences.h" +#include "nsIOService.h" #endif // !defined(MOZILLA_XPCOMRT_API) #include "nsASocketHandler.h" #include "nsError.h" @@ -1065,7 +1066,16 @@ nsSocketTransportService::DoPollIteration(bool wait, TimeDuration *pollDuration) // Measures seconds spent while blocked on PR_Poll uint32_t pollInterval; - int32_t n = Poll(wait, &pollInterval, pollDuration); + int32_t n = 0; +#if !defined(MOZILLA_XPCOMRT_API) + if (!gIOService->IsNetTearingDown()) { + // Let's not do polling during shutdown. + n = Poll(wait, &pollInterval, pollDuration); + } +#else + n = Poll(wait, &pollInterval, pollDuration); +#endif // defined(MOZILLA_XPCOMRT_API) + if (n < 0) { SOCKET_LOG((" PR_Poll error [%d] os error [%d]\n", PR_GetError(), PR_GetOSError())); diff --git a/netwerk/protocol/http/nsHttpConnection.cpp b/netwerk/protocol/http/nsHttpConnection.cpp index dcb877ee949a..968938855c89 100644 --- a/netwerk/protocol/http/nsHttpConnection.cpp +++ b/netwerk/protocol/http/nsHttpConnection.cpp @@ -558,7 +558,7 @@ nsHttpConnection::AddTransaction(nsAHttpTransaction *httpTransaction, } void -nsHttpConnection::Close(nsresult reason) +nsHttpConnection::Close(nsresult reason, bool aIsShutdown) { LOG(("nsHttpConnection::Close [this=%p reason=%x]\n", this, reason)); @@ -596,7 +596,8 @@ nsHttpConnection::Close(nsresult reason) // socket with data pending. TLS is a classic case of this where // a Alert record might be superfulous to a clean HTTP/SPDY shutdown. // Never block to do this and limit it to a small amount of data. - if (mSocketIn) { + // During shutdown just be fast! + if (mSocketIn && !aIsShutdown) { char buffer[4000]; uint32_t count, total = 0; nsresult rv; diff --git a/netwerk/protocol/http/nsHttpConnection.h b/netwerk/protocol/http/nsHttpConnection.h index 1b9db711f3f4..bdf9a7cc6494 100644 --- a/netwerk/protocol/http/nsHttpConnection.h +++ b/netwerk/protocol/http/nsHttpConnection.h @@ -77,7 +77,7 @@ public: nsresult Activate(nsAHttpTransaction *, uint32_t caps, int32_t pri); // Close the underlying socket transport. - void Close(nsresult reason); + void Close(nsresult reason, bool aIsShutdown = false); //------------------------------------------------------------------------- // XXX document when these are ok to call diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.cpp b/netwerk/protocol/http/nsHttpConnectionMgr.cpp index 76d04539bce1..dc5d8fe8234f 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp +++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp @@ -998,7 +998,7 @@ nsHttpConnectionMgr::ShutdownPassCB(const nsACString &key, ent->mActiveConns.RemoveElementAt(0); self->DecrementActiveConnCount(conn); - conn->Close(NS_ERROR_ABORT); + conn->Close(NS_ERROR_ABORT, true); NS_RELEASE(conn); }