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

Heads Up: Ajax Post hangs when initializing Fileupload in the wrong order. #9

Closed
cavpollo opened this issue Aug 25, 2016 · 2 comments
Closed

Comments

@cavpollo
Copy link

cavpollo commented Aug 25, 2016

I have a page with the following ajax post request:

$.ajax({
  type: "POST",
  url: "/my/some_id/path/create",
  data: some_data,
  success: function () {
    //Do something
  },
  fail: function () {
    console.log("fail");
  }
});

It was working just fine until a couple days ago, just before I tried to use this library. The library did indeed work as expected, but using it seemed to have negative consequences on existing functionality. The previously mentioned request hanged for about a minute. Then, although the browser would not receive anything, my app would raise this error:

Error: request aborted
  at IncomingMessage.onAborted (/home/cavpollo/my_app/node_modules/body-parser/node_modules/raw-body/index.js:269:10)
  at emitNone (events.js:68:13)
  at IncomingMessage.emit (events.js:167:7)
  at IncomingMessage.wrapped (/home/cavpollo/my_app/node_modules/newrelic/lib/transaction/tracer/index.js:161:28)
  at IncomingMessage.wrappedEmit [as emit] (/home/cavpollo/my_app/node_modules/newrelic/lib/transaction/tracer/index.js:198:46)
  at abortIncoming (_http_server.js:281:11)
  at Socket.serverSocketCloseListener (_http_server.js:294:5)
  at emitOne (events.js:83:20)
  at Socket.emit (events.js:170:7)
  at TCP._onclose (net.js:470:12)

After some debugging I came to realize that the problem was this line in my app initialization:

var express = require('express');
var fileUpload = require('express-fileupload');
var bodyParser = require('body-parser');
var app = express();

//Some irrelevant code

app.use(fileUpload()); // <------------- This line

//Some more irrelevant code

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());

Just commenting the line allowed me to do the Ajax Post call without problems... so then I thought, what if we switch things around?

var express = require('express');
var fileUpload = require('express-fileupload');
var bodyParser = require('body-parser');
var app = express();

//Some irrelevant code again

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(fileUpload());

It turns out that initializing things this way results in no errors and things working as expected.

Just a friendly heads up to anybody who stumbles on this problem. I was using version express-fileupload verison 0.0.5, express 4.14.0 and body-parser 1.13.3, if it is of any help.

@richardgirges
Copy link
Owner

Thanks for the heads up on this @cavpollo, I'll notate in the README that app.use(fileUpload()); must be placed after app.use(bodyParser...) for all versions of this package. And look into fixing the issue in a subsequent release. Keeping this ticket open until then.

eyalliebermann pushed a commit to Midburn/spark that referenced this issue Jan 4, 2017
* commit 'a5cb9a50f18b6dd0958773cf73e5632ac6a59bf7':
  Fix comment
  Move express-fileupload middleware after others, following instructions at richardgirges/express-fileupload#9
@richardgirges
Copy link
Owner

Closing this one out, as we have to tickets for the same issue. Refer to #11 to track progress on this issue.

This was referenced Nov 18, 2019
richardgirges pushed a commit that referenced this issue Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants