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: framework fails to shutdown gracefully when exit code is a string #545

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

garethgeorge
Copy link
Contributor

Despite the Node.js docs indicating that the exit code should always be a number it seems this is unchecked and, in fact, process.exit may be called with a string value.

Verified experimentally:

// test.js
const process = require("process");

process.on('exit', function(code) {
   console.log(typeof code);
   console.log(code);
});

process.exit('abc');
// output
string
abc

Some Cloud Function users report errors on shutdown when either their code or a dependency calls process.exit with a string value. To account for this the exit code check is updated to use string comparison to account for the possibility of a string exit code.

@conventional-commit-lint-gcf
Copy link

conventional-commit-lint-gcf bot commented Jun 15, 2023

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@garethgeorge garethgeorge force-pushed the garethgeorge/exitcode branch 2 times, most recently from 9e7a788 to a225134 Compare June 16, 2023 00:02
@garethgeorge garethgeorge changed the title Fix functions-framework fails to close gracefully when exit code is a string fix: framework fails to shutdown gracefully when exit code is a string Jun 16, 2023
Copy link
Contributor

@HKWinterhalter HKWinterhalter left a comment

Choose a reason for hiding this comment

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

Any testing for this?

@garethgeorge
Copy link
Contributor Author

garethgeorge commented Jun 21, 2023

No testing at the moment, it's unclear how we should approach testing this (beyond local exploratory testing). We don't have process lifecycle tests specific to node.js and mocha doesn't support this type of test.

I think we could possibly try to add a test that simulates emitting the event, I'm also fine with relying on exploratory tests and our conformance test coverage which should be exercising the full process lifecycle. WDYT?

@garethgeorge garethgeorge force-pushed the garethgeorge/exitcode branch from a225134 to 9384474 Compare July 6, 2023 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants