Defer property seems to be causing multiple upload requests. #706

Closed
aventuralabs opened this Issue Dec 11, 2012 · 7 comments

Comments

Projects
None yet
2 participants
@ghost

ghost commented Dec 11, 2012

In main.js, I have:

app.use(express.bodyParser({defer:true}));
...
app.post('/pictures/upload', photos.uploadPic);

In photos.js, I have

req.form.on('progress', function (received, expected) {
    ...
});
...
req.form.on('end', function() {
    // omitting error handling code for clarity
    res.status(200).send("Success");
});

Two major issues:

  1. For large uploads, "/pictures/upload" request is occurring multiple times, but only when defer is set to true. I have monitored outgoing network connections from the browser, and only one "upload" request is reported.
  2. Even more problematic, the request events are only being processed when dealing with certain browsers. I am using jquery-file-uploader and investigating more in-depth on the client side (reporting it in this issue solely in case the issues are linked).
Member

tj commented Dec 11, 2012

if you dont have async stuff going on between bodyParser with defer as true and wherever you happen to do req.form.on() those events should be fine, but keep in mind with node streams as they are today you can lose events if you're not listening for them right away, the defer portion itself doesn't actually do anything else

@ghost

ghost commented Dec 11, 2012

Thx for the feedback. I'll try moving the image handling up the middleware chain.

As to the bigger issue though, any ideas why the presence of "defer" might be causing multiple calls to the router? Although the browser is showing only a single call, I'm wondering if either:
- processing is deferred too long, a timeout may be occurring.
- the request is coming in multipart parts (3mb file, not too large), and defer is causing the request to be re-handled each time

I've avoided posting on this issue as I can't seem to nail down the cause. For example, if I use express.bodyParser on my local box, everything is peachy, but when deployed to nodejitsu everything falls apart. Checked versioning on all required packages, etc. I finally had to strip the middleware from the source code and insert it into my own - this strangely fixed everything. They believe that the bug lies in the package, I frankly don't have the foggiest idea.

Member

tj commented Dec 11, 2012

did you check if it's just the favicon or something weird like that? seems odd if it's actually issuing the multipart request several times, but that may also be an app-specific bug, doubt it has anything to do with connect or node

@ghost

ghost commented Dec 12, 2012

Per your recommendations, I checked all of those. It actually appears that the errors are occurring in connect.limit('5mb'). The bytes received are registering as far too large. The request is being repeatedly closed and re-opened as a result (net impact being 4 of the same pictures uploading simultaneously).

I'm checking for potential errors in the jquery-uploader as well.

@ghost

ghost commented Dec 12, 2012

Sorry, I should add that the files are smaller than the limit (3mb file with 5mb limit)

Member

tj commented Dec 12, 2012

interesting yeah it definitely sounds like an issue with that library, I've never seen that behaviour with the browser, connect certainly isn't asking for it haha, so i think we're safe to close

@ghost

ghost commented Dec 12, 2012

Agreed - thanks for the help and sorry for the red herring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment