bug 1038304 - websockets offline hang r=sworkman
authorPatrick McManus <mcmanus@ducksong.com>
Thu, 17 Jul 2014 11:56:38 -0400
changeset 216893 0fd5c666d35cca02d9a15151321928e4bddaccd4
parent 216892 a0e306c8d5be9f67b2320f55bbfbc0d4e27bf212
child 216894 69615044a960e09d24d46aa113b0410651b63b20
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman
bugs1038304
milestone33.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 1038304 - websockets offline hang r=sworkman
netwerk/protocol/websocket/WebSocketChannel.cpp
netwerk/test/unit/test_websocket_offline.js
netwerk/test/unit/xpcshell.ini
--- a/netwerk/protocol/websocket/WebSocketChannel.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannel.cpp
@@ -2420,21 +2420,26 @@ WebSocketChannel::OnProxyAvailable(nsICa
 
   nsAutoCString type;
   if (NS_SUCCEEDED(status) && pi &&
       NS_SUCCEEDED(pi->GetType(type)) &&
       !type.EqualsLiteral("direct")) {
     LOG(("WebSocket OnProxyAvailable [%p] Proxy found skip DNS lookup\n", this));
     // call DNS callback directly without DNS resolver
     OnLookupComplete(nullptr, nullptr, NS_ERROR_FAILURE);
-    return NS_OK;
+  } else {
+    LOG(("WebSocketChannel::OnProxyAvailable[%] checking DNS resolution\n", this));
+    nsresult rv = DoAdmissionDNS();
+    if (NS_FAILED(rv)) {
+      LOG(("WebSocket OnProxyAvailable [%p] DNS lookup failed\n", this));
+      // call DNS callback directly without DNS resolver
+      OnLookupComplete(nullptr, nullptr, NS_ERROR_FAILURE);
+    }
   }
 
-  LOG(("WebSocketChannel::OnProxyAvailable[%] checking DNS resolution\n", this));
-  DoAdmissionDNS();
   return NS_OK;
 }
 
 // nsIInterfaceRequestor
 
 NS_IMETHODIMP
 WebSocketChannel::GetInterface(const nsIID & iid, void **result)
 {
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_websocket_offline.js
@@ -0,0 +1,45 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+// checking to make sure we don't hang as per 1038304
+// offline so url isn't impt
+var url = "ws://localhost";
+var chan;
+var offlineStatus;
+
+var listener = {
+  onAcknowledge: function(aContext, aSize) {},
+  onBinaryMessageAvailable: function(aContext, aMsg) {},
+  onMessageAvailable: function(aContext, aMsg) {},
+  onServerClose: function(aContext, aCode, aReason) {},
+  onStart: function(aContext)
+  {
+    // onStart is not called when a connection fails
+    do_check_true(false);
+  },
+  onStop: function(aContext, aStatusCode)
+  {
+    do_check_neq(aStatusCode, Cr.NS_OK);
+    Services.io.offline = offlineStatus;
+    do_test_finished();
+  }
+};
+
+function run_test() {
+  offlineStatus = Services.io.offline;
+  Services.io.offline = true;
+
+  try {
+    chan = Cc["@mozilla.org/network/protocol;1?name=ws"].
+      createInstance(Components.interfaces.nsIWebSocketChannel);
+    var uri = Services.io.newURI(url, null, null);
+    chan.asyncOpen(uri, url, listener, null);
+    do_test_pending();
+  } catch (x) {
+    dump("throwing " + x);
+    do_throw(x);
+  }
+}
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -337,8 +337,9 @@ skip-if = os == "android"
 # disable this test on all android versions, even though it's enabled on 2.3+ in
 # the wild.
 skip-if = os == "android"
 [test_signature_extraction.js]
 run-if = os == "win"
 [test_udp_multicast.js]
 [test_redirect_history.js]
 [test_reply_without_content_type.js]
+[test_websocket_offline.js]