Skip to content

Commit

Permalink
Ensure req.send is not called until an error handler is registered wh…
Browse files Browse the repository at this point in the history
…en creating readable streams
  • Loading branch information
jeskew committed May 8, 2017
1 parent 6929f7d commit b6f5b65
Show file tree
Hide file tree
Showing 4 changed files with 1,208 additions and 1,136 deletions.
10 changes: 5 additions & 5 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ AWS.Request = inherit({

if (AWS.HttpClient.streamsApiVersion === 2) {
stream = new streams.PassThrough();
req.send();
process.nextTick(function() { req.send(); });
} else {
stream = new streams.Stream();
stream.readable = true;
Expand All @@ -579,6 +579,10 @@ AWS.Request = inherit({
});
}

this.on('error', function(err) {
stream.emit('error', err);
});

this.on('httpHeaders', function streamHeaders(statusCode, headers, resp) {
if (statusCode < 300) {
req.removeListener('httpData', AWS.EventListeners.Core.HTTP_DATA);
Expand Down Expand Up @@ -652,10 +656,6 @@ AWS.Request = inherit({
}
});

this.on('error', function(err) {
stream.emit('error', err);
});

return stream;
},

Expand Down
14 changes: 12 additions & 2 deletions test/helpers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b6f5b65

Please sign in to comment.