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

fix: do not err on process exit #144

Closed
wants to merge 2 commits into from
Closed

fix: do not err on process exit #144

wants to merge 2 commits into from

Conversation

grant
Copy link
Contributor

@grant grant commented May 22, 2020

Fixes: #22 #143

This change the behavior the process exit event handler.
I don't know exactly why we have a latestRes modification here or if it's needed. I would assume a process exit does not need to send the latest HTTP response as an exit would not naturally happen.

Before

Serving function...
Function: function
URL: http://localhost:8080/
^CReceived SIGINT
Error: Process exited with code 0
    at process.<anonymous> (<folder>/node_modules/@google-cloud/functions-framework/build/src/invoker.js:396:29)
    at process.emit (events.js:203:13)
    at process.EventEmitter.emit (domain.js:471:20)
    at process.exit (internal/process/per_thread.js:158:15)
    at Server.<anonymous> (<folder>/node_modules/@google-cloud/functions-framework/build/src/invoker.js:402:29)
    at Object.onceWrapper (events.js:291:20)
    at Server.emit (events.js:203:13)
    at Server.EventEmitter.emit (domain.js:471:20)
    at emitCloseNT (net.js:1572:8)
    at processTicksAndRejections (internal/process/task_queues.js:77:11)

After

Serving function...
Function: function
URL: http://localhost:8080/
^CReceived SIGINT
Process exited with code 0

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
@grant grant requested a review from hdp617 May 22, 2020 01:50
@grant grant self-assigned this May 22, 2020
src/invoker.ts Show resolved Hide resolved
@grant grant requested a review from hdp617 June 2, 2020 23:19
process.on('exit', code => {
logAndSendError(new Error(`Process exited with code ${code}`), latestRes);
process.on('SIGINT', code => {
console.log(`Process exited with code ${code}`);
});

['SIGINT', 'SIGTERM'].forEach(signal => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SIGINT is also handled here. Could you please update this?

@@ -258,8 +258,8 @@ export class ErrorHandler {
logAndSendError(err, latestRes, killInstance);
});

process.on('exit', code => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would remove error logging when the process exits from user's function.

I do think we should not log and send error when process exits normally though. How about checking the status code and only logAndSendError for non-0 ones? Or handing SIGINT before exit?

@hdp617
Copy link
Contributor

hdp617 commented Jun 18, 2020

@grant What's the status of this PR?

@grant
Copy link
Contributor Author

grant commented Jun 18, 2020

@grant What's the status of this PR?

I don't know how to test this change, don't want to break GCF, and haven't continued with it.
Do you know the solution here?

@grant
Copy link
Contributor Author

grant commented Aug 5, 2020

This PR is outdated and fixed with #126.

@grant grant closed this Aug 5, 2020
@grant grant deleted the grant_exit_smooth branch August 5, 2020 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

process.on('exit', ... always errors
3 participants