aws-sdk-js: TypeError: Cannot read property 'push' of undefined
I’m getting the following error when using release v2.36.0
TypeError: Cannot read property 'push' of undefined
at Request.HTTP_DATA (/user_code/node_modules/aws-sdk/lib/event_listeners.js:321:34)
at Request.callListeners (/user_code/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/user_code/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/user_code/node_modules/aws-sdk/lib/request.js:673:14)
at IncomingMessage.onReadable (/user_code/node_modules/aws-sdk/lib/event_listeners.js:231:32)
at emitNone (events.js:86:13)
at IncomingMessage.emit (events.js:185:7)
at emitReadable_ (_stream_readable.js:432:10)
at emitReadable (_stream_readable.js:426:7)
at readableAddChunk (_stream_readable.js:187:13)
I’m making requests that look something like the following on an interval.
new AWS.CloudFormation().describeStacks({
StackName: stackName
}, function(err, data) {
if (err) {
console.log("error describing stack " + stackName);
console.log(err)
return;
}
});
Theres errors appear to be pretty sporadic so Im not sure if they are considered normal errors or not.
There error appears to stem from a buffers array being undefined while handling an HTTP_DATA
event. The reference to the array appears to get defined in another call to add
for HTTP_HEADERS
here.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (5 by maintainers)
Ran into the same issue using a promise that wrapped the promise from request.promise(). Issue was resolved by switching to callbacks. I’d recommend just using the callback and wrapping it in a promise to use this without issue until this is resolved.
I hit this error as well, and upon digging in I found that it was because I was calling
request.promise()
twice. Turns out that promise() calls request.runTo, which does not play nice on multiple calls because it will cause the state machine to transition with the same state twice. If that state happens to besend
, then it will hit the event listener for send twice. That will make two network requests with the same request & response object. Naturally, one will complete first and delete the buffers. When the second one completes, the buffers won’t exist anymore and that’s where you get theCannot read property 'push' of undefined
error.It would be nice if there was some logic to prevent running the state machine twice, as this was not an easy bug to track down. Especially since I don’t see anything in the docs that says “btw if you call promise() twice you’re taking a trip to crazytown”.
I would also believe that there are cases where
runTo()
is called from one of the other locations and then callingpromise()
once is enough to hose you.Thanks so much @stevearc. This exactly describes the errors I’ve been seeing. So, for instance I’m grabbing some items from s3, and using Promise.all to collect the items and do something with them in a lambda. If I’m mapping over a collection of params items, feeding each of those into s3.getObject, then calling promise() on each of those to generate an array of promises for Promise.all, I’d run into this problem, correct?
I am having similar issue with v2.190.0 on node v8.9.1. The promise API keep failing and change to callback API fixes the issue
Similar issue, on listObjectsV2, the .promise() call sometimes wouldn’t return at all, hanging completely. The errors seemed to not be reported to the reject/catch handler. I’ve converted my code to manually create a promise and use the callback function parameter for this method. If I try to pass a callback function, and call .promise() I see this error. Since removing .promise() I haven’t had any issues other than lengthy code.