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

Issue uploading file with io.js or node > 0.11.6 #2427

Closed
dschenkelman opened this issue Feb 21, 2015 · 10 comments
Closed

Issue uploading file with io.js or node > 0.11.6 #2427

dschenkelman opened this issue Feb 21, 2015 · 10 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@dschenkelman
Copy link
Contributor

When trying to migrate my app to either node 0.12 or io.js (any version) I started seeing an issue that is not always reproduced (seems to be a race condition of some sort) when uploading files.

Basically, when uploading a file larger than that allowed by the payload maxBytes we get an error:

{ [Error: write EPIPE]
  code: 'EPIPE',
  errno: 'EPIPE',
  syscall: 'write',
  address: undefined }

This does not happen if the size of the file is under the limit.

I put together a repository that reproduces the issue: https://github.com/dschenkelman/hapi-upload-iojs.

@pandeysoni
Copy link

You can visit for working code in https://github.com/pandeysoni/Hapi-file-upload-download

/*
 * upload file
 */

exports.uploadFile = {
    payload: {
        maxBytes: 209715200,
        output: 'stream',
        parse: false
    },
    handler: function(requset, reply) {
        var form = new multiparty.Form();
        form.parse(requset.payload, function(err, fields, files) {
            if (err) return reply(err);
            else upload(files, reply);
        });
    }
};

/*
 * upload file function
 */

var upload = function(files, reply) {
    fs.readFile(files.file[0].path, function(err, data) {
        checkFileExist();
        fs.writeFile(Config.MixInsideFolder + files.file[0].originalFilename, data, function(err) {
            if (err) return reply(err);
            else return reply('File uploaded to: ' + Config.MixInsideFolder + files.file[0].originalFilename);

        });
    });
};

@dschenkelman
Copy link
Contributor Author

Hey @pandeysoni,

Thanks for the example. Just to clarify, it is not that I'm not able to get file upload to work, I have a working application using 0.10.30.

The issue is that in versions of node > 0.11.6 and in io.js instead of always getting a 400 in the request I sometimes get the error mentioned above.

@pandeysoni
Copy link

Hi @dschenkelman, I cloned your github repo and i tested with node : v0.10.31 and it is throwing error with version 0.10 also.

@dschenkelman
Copy link
Contributor Author

Have just tried running 10 times with node 0.10.30 and did not get the error. Running 5 times with io.js 1.2.0 I got the error 4 times.

@kanongil
Copy link
Contributor

I had a look at this. I am unable to reproduce the error on node 0.12. I ran the client 50'ish times.

Which system are you on?

@pandeysoni
Copy link

It's on windows 7.

@dschenkelman
Copy link
Contributor Author

Sorry forgot to include it here, had added it to the sample project. Ubuntu 14.04.1 LTS.

kanongil added a commit to kanongil/hapi that referenced this issue Feb 24, 2015
@kanongil
Copy link
Contributor

Ok, so this is a very tricky issue. This is indeed a bug in Hapi and in fact not related to new versions of node. I have been able to create a test case which fails on both 0.10, 0.12, and io.js.

The error occurs when the client payload is not consumed on a request with the connection: close header. I have created a PR #2429 for the test and a potential fix.

@kanongil kanongil added the bug Bug or defect label Feb 24, 2015
@dschenkelman
Copy link
Contributor Author

Wow, you were quick to find that. I spent some time going through Hapi's code but couldn't figure out the cause.

I tried the fix in the machine were I could reproduce the issue and it seems to be fixed.

Thanks a lot for the time and effort.

@hueniverse hueniverse added this to the 8.3.0 milestone Mar 5, 2015
hueniverse pushed a commit that referenced this issue Mar 5, 2015
@hueniverse hueniverse assigned hueniverse and unassigned kanongil Mar 6, 2015
@kanongil
Copy link
Contributor

So, it's 2 years later now and it seems that this is in fact a node.js bug, which I have reported here: nodejs/node#12339.

The serverside fix just mitigated the client-side issue.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

4 participants