Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$.ajax DELETE requests hang due to "keep-alive" header #2069

Closed
brandoncarl opened this issue Apr 23, 2014 · 15 comments
Closed

$.ajax DELETE requests hang due to "keep-alive" header #2069

brandoncarl opened this issue Apr 23, 2014 · 15 comments

Comments

@brandoncarl
Copy link

When issuing a same-origin AJAX delete via jQuery, subsequent calls to the server via the same client are hanging.

Using Express 3.5.1, jQuery 1.11.0, and Chrome 33.x (also occurs in FF28).

To replicate:

  1. Create directory with code below and install Express dependency
  2. node main.js
  3. Visit localhost:5000 in Chrome 33
  4. Click on simulated deletion link
  5. Wait for a moment, and refresh
  6. In the Network region, Chrome will handle the DELETE request ok, but the subsequent server call will stay as "pending"
// Dependencies
var http = require('http'),
    express = require('express');

// Basic app
var app = express();

// Logging (for debugging), and parsing dependencies
app.use(express.logger());
app.use(express.json());
app.use(express.urlencoded());
app.use(express.cookieParser());
app.use(express.methodOverride());

// Simple home page
app.get("/", function(req, res) {
  var head   = "<head><script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script></head>",
      body   = "<a id='link' style='text-decoration:underline;cursor:pointer;'>Click here to simulate delete</a>, wait a second, then try refreshing.",
      params = {
        url  : "/item/5",
        type : "DELETE"
      }
      ajax = "<script>$(function() { $('#link').click(function() { $.ajax(" + JSON.stringify(params) + "); }); });</script>"

  res.send("<html>" + head + "<body>" + body + ajax + "</body></html>");

});

// Simulated deletion
app.del("/item/:id", function(req, res) {
  res.send(204);
});

// Make the server listen
var server = http.createServer(app).listen(5000);

The solution is to use res.set("Connection", "close").send(204). That said, it's not clear to me that the user should need to "force close" the connection so much as prevent the "keep-alive" header from being used.

@defunctzombie
Copy link
Contributor

There are too many things in play here. Maybe consider removing the jquery ajax call and using builtin stuff. jQuery could be doing something.

Also, what do you mean by subsequent calls hang? Subsequent ajax calls? Or subsequent page reloads?

Try isolating the issue more. There is a lot of extra fluff (middleware, etc) in the example which again broadens the problem space.

@brandoncarl
Copy link
Author

Hi Roman - I have isolated the issue. I built the same server using Flask in Python and compared the subsequent headers (Flask works). I've also resolved the issue by closing the connection (as indicated in the solution). I've included all the above in order to let you know that no obvious middleware was missing.

By subsequent calls hanging, I mean that any subsequent call, even hitting refresh, completely hangs.

@defunctzombie
Copy link
Contributor

Just tried it on my machine using express 3.5.1 and your example worked. I see the delete and I can refresh just fine. I would also recommend disabling any extensions you might have (try this in incognito mode).

@brandoncarl
Copy link
Author

Interesting...thanks for trying it.

I did disable all extensions and also tried in incognito mode. Chromium 34 works, but Chrome 33 and FF 28 did not.

@brandoncarl
Copy link
Author

Not trying to ignore suggestions, just that I spent 10 hours on this, so had already tried a lot of things before isolating.

@brandoncarl
Copy link
Author

I'm wondering if #2060 may be related. Using v0.10.25 FYI. I'll try to replicate on another machine.

@defunctzombie
Copy link
Contributor

I'll take a look in Firefox a bit later. First I gotta find a way to make
it fail ;)
On Apr 23, 2014 2:34 PM, "Brandon Carl" notifications@github.com wrote:

I'm wondering if #2060 https://github.com/visionmedia/express/pull/2060may be related. Using v0.10.25 FYI. I'll try to replicate on another
machine.


Reply to this email directly or view it on GitHubhttps://github.com//issues/2069#issuecomment-41197817
.

@brandoncarl
Copy link
Author

So, it appeared that it was Sophos running in the background, distorting the requests. Strangely Safari wasn't having a problem. Permanently uninstalled. Sorry for the red herring!

@cahrens
Copy link

cahrens commented Jul 11, 2014

I am having the exact same issue (any operation after a DELETE hangs on Firefox and Chrome, fine on Safari). I tried uninstalling Sophos, but it did not fix the issue for me. @brandoncarl do you have any additional information?

@dougwilson
Copy link
Contributor

@cahrens when you go to http://jsfiddle.net/icodeforlove/75gUy/ do you see two alerts or only one?

@cahrens
Copy link

cahrens commented Jul 11, 2014

Just one.

@dougwilson
Copy link
Contributor

@cahrens if you only see one alert, the second DELETE is hanging on jsfiddle's web site, which does not even use express, so your machine is clearly still broken. You'll have to fix your machine, but it's not an express issue.

@cahrens
Copy link

cahrens commented Jul 11, 2014

Sorry, I should have confessed that I am not using express. This was the only post that I could find when searching that exactly replicated the issue I am seeing. Thanks for putting together the jsfiddle example.

@dougwilson
Copy link
Contributor

Sorry, I should have confessed that I am not using express. This was the only post that I could find when searching that exactly replicated the issue I am seeing.

Ah, gotcha.

Thanks for putting together the jsfiddle example.

Credit goes to this person: http://openforum.sophos.com/t5/Sophos-Anti-Virus-for-Mac-Home/Sophos-9-0-7-Web-Protection-HTTP-DELETE-bug/td-p/15823 :)

@cahrens
Copy link

cahrens commented Jul 11, 2014

Following up, the way that I tried uninstalling Sophos did not actually uninstall it. Disabling "Web Protection" in Sophos did solve my problem.

@expressjs expressjs locked and limited conversation to collaborators Jul 11, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants