Bug 1400563: clean up SCTP shutdown r=drno
authorRandell Jesup <rjesup@jesup.org>
Wed, 11 Oct 2017 00:40:21 -0400
changeset 428144 955cbee8d3d74868e545e35180776774f24d2834
parent 428143 42e13f7fafc6cdd397daee31bb62bc283092abb0
child 428145 629e5c24737ba0e38ef54ee2515b1d79245b9289
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
reviewersdrno
bugs1400563
milestone58.0a1
Bug 1400563: clean up SCTP shutdown r=drno
netwerk/sctp/datachannel/DataChannel.cpp
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -102,16 +102,17 @@ public:
 private:
   // The only instance of DataChannelShutdown is owned by the observer
   // service, so there is no need to call RemoveObserver here.
   virtual ~DataChannelShutdown() = default;
 
 public:
   NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic,
                      const char16_t* aData) override {
+    // Note: MainThread
     if (strcmp(aTopic, "xpcom-will-shutdown") == 0) {
       LOG(("Shutting down SCTP"));
       if (sctp_initialized) {
         usrsctp_finish();
         sctp_initialized = false;
       }
       nsCOMPtr<nsIObserverService> observerService =
         mozilla::services::GetObserverService();
@@ -290,22 +291,16 @@ DataChannelConnection::Destroy()
 
   MutexAutoLock lock(mLock);
   // If we had a pending reset, we aren't waiting for it - clear the list so
   // we can deregister this DataChannelConnection without leaking.
   ClearResets();
 
   MOZ_ASSERT(mSTS);
   ASSERT_WEBRTC(NS_IsMainThread());
-  // Must do this in Destroy() since we may then delete this object.
-  // Do this before dispatching to create a consistent ordering of calls to
-  // the SCTP stack.
-  usrsctp_deregister_address(static_cast<void *>(this));
-  LOG(("Deregistered %p from the SCTP stack.", static_cast<void *>(this)));
-
   // Finish Destroy on STS thread to avoid bug 876167 - once that's fixed,
   // the usrsctp_close() calls can move back here (and just proxy the
   // disconnect_all())
   RUN_ON_THREAD(mSTS, WrapRunnable(RefPtr<DataChannelConnection>(this),
                                    &DataChannelConnection::DestroyOnSTS,
                                    mSocket, mMasterSocket),
                 NS_DISPATCH_NORMAL);
 
@@ -322,16 +317,19 @@ DataChannelConnection::Destroy()
 void DataChannelConnection::DestroyOnSTS(struct socket *aMasterSocket,
                                          struct socket *aSocket)
 {
   if (aSocket && aSocket != aMasterSocket)
     usrsctp_close(aSocket);
   if (aMasterSocket)
     usrsctp_close(aMasterSocket);
 
+  usrsctp_deregister_address(static_cast<void *>(this));
+  LOG(("Deregistered %p from the SCTP stack.", static_cast<void *>(this)));
+
   disconnect_all();
 }
 
 bool
 DataChannelConnection::Init(unsigned short aPort, uint16_t aNumStreams, bool aMaxMessageSizeSet,
                             uint64_t aMaxMessageSize)
 {
   struct sctp_initmsg initmsg;