-
Notifications
You must be signed in to change notification settings - Fork 187
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
fix(core): fix another scenario that causes hanging (11.x) #513
Conversation
@@ -55,8 +58,9 @@ const runLocally = (event) => { | |||
handler(event, {}, (err, data) => { | |||
if (err) { | |||
reject(err); | |||
} else { | |||
resolve(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed a problem while I was here. We should call either resolve
or reject
but not both.
perform: (z, bundle) => { | ||
https | ||
.request(`${HTTPBIN_URL}/status/418`, (res) => { | ||
let body = ''; | ||
res.on('data', (d) => { | ||
body += d; | ||
}); | ||
res.on('end', () => { | ||
// Set a global variable so we have something to assert in the test | ||
// to prove we can reach here | ||
process.teapot = body; | ||
// body === "I'm a teapot!" | ||
}); | ||
}) | ||
.end(); | ||
return { message: 'ok' }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code has essentially the same effect as the "double callback" example I wrote in the PR description.
@xavdid can you also review/approve this PR when you're online? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry! I approved the other one and I guess I missed this one in the shuffle.
I'll hold off merging mine so you have a clean path to get these out.
Related to #509, #490, and https://github.com/zapier/zapier/issues/53430, this addresses another scenario that causes the Lambda handler to hang/freeze.
Suppose a converted app has this (bad) legacy script:
Notice how the
post_write
function returns immediately by callingcallback(null, { message: 'ok' })
while makes an outboundz.request()
and callscallback
asynchronously.When legacy-scripting-runner promisifies this
post_write
function, thecallback
in thez.request
will come after the Lambda handler returns. Since we only end the logger once when the Lambda handler finishes, the HTTP logger corresponding to thez.request
call, which comes after the Lambda handler, will stay open and never end until a long timeout.To fix, we need to make sure to end any loggers allocated after the Lambda handler returns.