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

Chunked upload fail with 500 #152

Closed
compulim opened this issue Apr 8, 2012 · 2 comments
Closed

Chunked upload fail with 500 #152

compulim opened this issue Apr 8, 2012 · 2 comments
Labels

Comments

@compulim
Copy link

compulim commented Apr 8, 2012

I am hosting a iisnode on Azure with Microsoft official SDK and node.js 0.6.10.

It seems iisnode cannot process chunked upload. Here is the client and server code. (Note the comment line on client code)

Client Code

var http = require('http'),
    body = new Buffer('Testing 123', 'utf8'),
    req;

req = http.request({
    host: 'hostname',
    port: 80,
    method: 'POST',
    path: '/',
    headers: {
        //'Content-Length': body.length,
        'Content-Type': 'text/plain'
    }
}, function (res) {
    console.log('Server responded: ' + res.statusCode);
}).on('error', function (err) {
    console.log('Failed to connect to server: ' + ex);
});

req.end(body);

Server Code

var http = require('http'),
    port = process.env.port || parseInt(process.argv[2], 10);

http.createServer(function (req, res) {
    console.log(req.headers);

    req.on('data', function (chunk) {
        console.log('Received: ' + chunk.toString('utf8'));
    });

    req.on('end', function () {
        res.writeHead(200);
        res.end('Hello, World!');
    });

    req.on('close', function () {
        console.log('Closed prematurely.');
    });

    req.resume();
}).listen(port, function () {
    console.log('Echo server started and listening to port ' + port + '...');
});

When I run it with local node.exe, everything works fine. The client receive 200 and the server receive the string.

But when I run it with iisnode on Azure, it will return 500. And what I see on the server side:

iisnode log

Echo server started and listening to port \\.\pipe\0ed3a093-b0a0-44bb-b341-91d8947900e7...
{ connection: 'keep-alive',
  'transfer-encoding': 'chunked',
  'content-type': 'text/plain',
  host: 'hostname',
  'x-original-url': '/' }
Closed prematurely.

I enabled IIS Failed Request Tracing, and here is the rough log:

IIS Failed Request Tracing

177 - GENERAL_REQUEST_ENTITY
Buffer Testing 12

178 - NOTIFY_MODULE_COMPLETION
ModuleName iisnode
Notification 128,
fIsPostNotificationEvent false
CompletionBytes 11
ErrorCode 0
Notification EXECUTE_REQUEST_HANDLER
ErrorCode The operation completed successfully. (0x0)

179 - GENERAL_READ_ENTITY_START

180 - GENERAL_READ_ENTITY_END
BytesReceived 0
ErrorCode 2147942438
ErrorCode Reached the end of the file. (0x80070026)

181 - MODULE_SET_RESPONSE_ERROR_STATUS
ModuleName iisnode
Notification 128
HttpStatus 500
HttpReason Internal Server Error
HttpSubStatus 0
ErrorCode 109
ConfigExceptionInfo
Notification EXECUTE_REQUEST_HANDLER
ErrorCode The pipe has been ended. (0x6d)

But when I also send "Content-Length" along with my request, i.e. non-chunked mode, everything works fine. I receive this on iisnode log.

iisnode log with Content-Length set

{ connection: 'keep-alive',
  'content-length': '11',
  'content-type': 'text/plain',
  host: 'hostname',
  'x-original-url': '/' }
Received: Testing 123

Looks like either I have something wrong with my code, something wrong with Azure handling the request, or something wrong with iisnode.

@tjanczuk
Copy link
Owner

tjanczuk commented Apr 8, 2012

Thank you for the detailed report. I will look at this in about a week, as I am out of town right now.

@tjanczuk
Copy link
Owner

The issue is that IIS automatically decodes chunked transfer encoding of the request entity body, while iisnode module does not re-apply chunked encoding when relaying the message to the node.exe process.

The fix is for iisnode to re-apply chunking when forwarding messages to node.exe, as long as the original request message that IIS received was chunked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants