Closed Bug 1140284 Opened 9 years ago Closed 9 years ago

Can not connect to localhost after proxy change in offline mode

Categories

(Core :: Networking: DNS, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla39
Tracking Status
firefox39 --- fixed
b2g-v2.0 --- fixed
b2g-v2.0M --- fixed
b2g-v2.1 --- fixed
b2g-v2.1S --- fixed
b2g-v2.2 --- fixed
b2g-master --- fixed

People

(Reporter: CuveeHsu, Assigned: bagder)

References

Details

Attachments

(1 file, 2 obsolete files)

STR
* browser
1. Use File -> "Offline Mode" to move to offline mode
2. Click Preference -> Advanced -> Network ->Cached Web Content -> Clear Now
3. Use Preference -> Advanced -> Network -> Connection -> Settings
   to change proxy to anyone different
4. Try to make a connection to 127.0.0.1/localhost through http

Actual result:
Show Offline mode

Expected result:
Try to make a connection if no http service is in localhost
Or show the page if localhost has a http service.

* Firefox OS
1. Enter Airplane mode
2. Use webIDE to change "network.proxy.type" to a different value
3. Use browser to make a connection to 127.0.0.1/localhost


Actual result:
Show "http://127.0.0.1 requires an Internet connection."

Expected result:
Show "A network error occurred while trying to reach the site."
Actually Shih-Chiang and I have found the root cause, and we need some suggestion.

The thing is changing proxy will restart the DNSService
https://dxr.mozilla.org/mozilla-central/source/netwerk/dns/nsDNSService2.cpp#592
https://dxr.mozilla.org/mozilla-central/source/netwerk/dns/nsDNSService2.cpp#964

However, becaouse of offline, the initialization bails out before nsHostResolver is created.
https://dxr.mozilla.org/mozilla-central/source/netwerk/dns/nsDNSService2.cpp#608

Therefore, DNSService.asyncResolve no longer works even if we try to connect to localhost
https://dxr.mozilla.org/mozilla-central/source/netwerk/dns/nsDNSService2.cpp#758

Hello Patrick and Ehsan:
Do we have risk if we don't check the online/offline when DNSService is initialing? 
We have done some experiment and behavior looks good.
Just push to try if anything is out of expectation:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=c98009b80da5

Or any suggestion to step advance?
Flags: needinfo?(mcmanus)
Flags: needinfo?(ehsan)
daniel is becoming master of on/offline.
Flags: needinfo?(mcmanus) → needinfo?(daniel)
Isn't this just a version of the good old Bug 339814?
Flags: needinfo?(daniel)
(In reply to Daniel Stenberg [:bagder] from comment #3)
> Isn't this just a version of the good old Bug 339814?

Yes, but comment 1 seems to have some concrete info on what causes it!
Flags: needinfo?(ehsan)
daniel, can you take it?
Assignee: nobody → daniel
I think we can avoid the Shutdown()/Init() loop for this case and only flush the caches? This seems to not make the problem trigger for me.

An alternative solution would be allow the Init() method to fire up the resolver even when in offline mode - and we might want that anyway for other prefs changes that I believe still need to restart the resolvers to take effect but yet we want it to work while offline.
The patch that introduced the delayed start of the resolver comes from Bug 614286 (by :ehsan), but unfortunately the discussion there mostly focuses on the socket transport service.
Theoretically we might switch to offline mode before the first initialization of nsDNSService. In this case, we'll still the same issue if we don't change the logic in https://dxr.mozilla.org/mozilla-central/source/netwerk/dns/nsDNSService2.cpp#608.
Good point, I did a little experiment with simply removing the check and starting the resolver unconditionally, which seemed to work fine in my manual tests but causes several test cases to fail:

--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -601,15 +601,10 @@ nsDNSService::Init()
 
     }
 
     nsDNSPrefetch::Initialize(this);
 
-    // Don't initialize the resolver if we're in offline mode.
-    // Later on, the IO service will reinitialize us when going online.
-    if (gIOService->IsOffline() && !gIOService->IsComingOnline())
-        return NS_OK;
-
     nsCOMPtr<nsIIDNService> idn = do_GetService(NS_IDNSERVICE_CONTRACTID);
 
     nsCOMPtr<nsIObserverService> obs =
         do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
Blocks: 339814
Here's the patch that starts the resolver unconditionally, even if offline, and the try-run for this: https://treeherder.mozilla.org/#/jobs?repo=try&revision=4f33b01f1a71

It also seems to fix the case when I tried it manually.

It is just a proof of concept still, could use some further cleaning up if we decide to go this path.
Attachment #8574560 - Attachment is obsolete: true
Ehsan, do you recall the details on why that removal of the unconditional start of the resolver as it seems bringing that back fixes this problem (and not unlikely for bug 339814 too).
Flags: needinfo?(ehsan)
(In reply to Daniel Stenberg [:bagder] from comment #11)
> Ehsan, do you recall the details on why that removal of the unconditional
> start of the resolver as it seems bringing that back fixes this problem (and
> not unlikely for bug 339814 too).

I made that change in bug 614286 because we used to crash if attempting to initialize this stuff before the STS.
Flags: needinfo?(ehsan)
Here's an official patch suggestion then. You OK with reviewing :ehsan - since you did this change before I figured you might be a good pair of eyes on this.

This patch starts the resolver even when when offline, to make 'localhost' still work.
Attachment #8574860 - Attachment is obsolete: true
Attachment #8575979 - Flags: review?(ehsan)
Attachment #8575979 - Flags: review?(ehsan) → review+
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/42ea2c7b3f6a
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla39
Comment on attachment 8575979 [details] [diff] [review]
v2-0001-Bug-1140284-start-the-resolver-even-when-offline-.patch

Note that this is actually desired for v2.1s and v2.0m; I'm not sure how this impacts landing flags and branches.

[Approval Request Comment]
Bug caused by (feature/regressing bug #): 
Not a regression.

User impact if declined: 
v2.1s and v2.0m really want this fix.  See bug 1169474 and/or bug 1169401 for more details.

Testing completed:
Trunk is happy, v2.1 and v2.0 are sad and the change is very simple.

Risk to taking this patch (and alternatives if risky):
No risk perceived.  The resolver service will initialize at startup (or on demand) when offline when it previously would not.  This is harmless and explicitly desired.
 
String or UUID changes made by this patch:
No changes.
Attachment #8575979 - Flags: approval-mozilla-b2g34?
Attachment #8575979 - Flags: approval-mozilla-b2g32?
Comment on attachment 8575979 [details] [diff] [review]
v2-0001-Bug-1140284-start-the-resolver-even-when-offline-.patch

Hi Ryan, 
I think this worth to be land on 2.0/2.1 and then cherry pick to 2.0M/2.1S. How do you think? :)
Flags: needinfo?(ryanvm)
Attachment #8575979 - Flags: approval-mozilla-b2g34?
Attachment #8575979 - Flags: approval-mozilla-b2g34+
Attachment #8575979 - Flags: approval-mozilla-b2g32?
Attachment #8575979 - Flags: approval-mozilla-b2g32+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: