Closed Bug 212820 Opened 21 years ago Closed 21 years ago

XMLHttpRequest locks up browser when grabbing synchronously

Categories

(Core :: XML, defect)

x86
All
defect
Not set
critical

Tracking

()

RESOLVED DUPLICATE of bug 190313

People

(Reporter: geofforama, Assigned: hjtoi-bugzilla)

References

()

Details

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030630 Mozilla Firebird/0.6 StumbleUpon/1.66
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030630 Mozilla Firebird/0.6 StumbleUpon/1.66

When using XMLHttpRequest synchronously in javascript, the browser will freeze
until the request is finished.  In this example:

http://www.stumbleupon.com/test.html

I get the xmlhttprequest to hit sleep.php, which is a PHP script that sleeps for
10 seconds.  Hitting the above page will causes the browser to freeze for 10
seconds while waiting for the xmlhttprequest to finish retrieving the response
xml.  CPU usage during the freeze is 100%.

The workaround is to use the async version of xmlhttprequest, but for anyone
hitting a page with a sync xmlhttprequest, their browser will lockup for as long
as network lag is.  And of course, using the async version needlessly
complicates your code.

I'm not sure if this probems exists outside of javascript.  I have seen it
happen on windows and linux, Mozilla 1.4 and early builds.

Reproducible: Always

Steps to Reproduce:
1.Go to http://www.stumbleupon.com/test.html
Actual Results:  
Browser locks up for 10 seconds, CPU usage is 100%

Expected Results:  
Browser should not lock up, nor should CPU usage be 100%.
I'm using the most recent FireFox 0.8 and tried the test page. Yes, the bug
exists. Actually I had a similar code in a webpage of mine. I'm using Windows XP
SP1. And even for localhost, it freezes for 3 or 4 seconds. The CPU usage
doesn't even let me switch tasks.

    var xml=new XMLHttpRequest();
    xml.open("GET",url,false);
    xml.setRequestHeader('Cache-control','no-cache');
    xml.send(null);
    document.getElementById(lyr).innerHTML=xml.responseText;

Same here (Mozilla 1.6/WinXP) - all open Mozilla windows hang.

It seems that this code doesn't work correct and turns into an empty loop:
http://lxr.mozilla.org/mozilla/source/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp#1336

1335   if (!(mState & XML_HTTP_REQUEST_ASYNC)) {
1336     while (mState & XML_HTTP_REQUEST_SYNCLOOPING) {
1337       modalEventQueue->ProcessPendingEvents();
1338     }

I think, ProcessPendingEvents() should be replaced by WaitForEvent() and
HandleEvent(), this will solve the issue with the CPU load. An event should be
posted to the event queue after deleting XML_HTTP_REQUEST_SYNCLOOPING flag - to
make sure that the loop really stops.

Preventing the browser from hanging while Send() executes will be much more
difficult to achieve...
This is a duplicate of bug 190313.

The preferred remediation is discussed in that bug and bug 189513 comment 2.

I intend to work on it, but I haven't found time recently.  If anyone else
begins work on it, please let me know.

*** This bug has been marked as a duplicate of 190313 ***
Status: UNCONFIRMED → RESOLVED
Closed: 21 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.