Skip to content

Add shell debugging and fix timeout issue #1932

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

Merged
merged 1 commit into from
Jan 22, 2020

Conversation

samtstern
Copy link
Contributor

Description

Scenarios Tested

Was able to successfully:

  • Set a breakpoint in a function with functions:shell
  • Run an emulated function with debugging on for more than the default timeout, no error
  • Run an emulated function with debugging off for more than the default timeout, got error

Used this test case for everything:

exports.helloWorld = functions
  .runWith({
    timeoutSeconds: 10
  })
  .https.onRequest((request, response) => {
    setTimeout(() => {
      response.send("Hello from Firebase!");
    }, 11 * 1000);
  });

Sample Commands

$ firebase functions:shell --help
Usage: firebase functions:shell [options]

launch full Node shell with emulated functions

Options:
  -p, --port <port>           the port on which to emulate functions (default: 5000)
  --inspect-functions [port]  emulate Cloud Functions in debug mode with the node 
                              inspector on the given port (9229 if not specified)
  -h, --help                  output usage information

@samtstern samtstern requested a review from bkendall January 22, 2020 19:14
@googlebot googlebot added the cla: yes Manual indication that this has passed CLA. label Jan 22, 2020
@samtstern samtstern requested a review from abeisgoat January 22, 2020 19:14

module.exports = function(options) {
options.port = parseInt(options.port, 10);

let debugPort = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let debugPort: number | undefined;

Setting something to undefined always feels dirty to me haha

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree but this is .js ... so I can't add types.

@@ -115,6 +115,13 @@ export class FunctionsEmulator implements EmulatorInstance {
// TODO: Would prefer not to have static state but here we are!
EmulatorLogger.verbosity = this.args.quiet ? Verbosity.QUIET : Verbosity.DEBUG;

// When debugging is enabled, the "timeout" feature needs to be disabled so that
// functions don't timeout while a breakpoint is active.
if (this.args.debugPort) {
Copy link
Contributor

Choose a reason for hiding this comment

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

lgtm, can't imagine anything going wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope to use a screenshot of this comment in a P0 bug one day.

@samtstern samtstern merged commit ce5ee52 into master Jan 22, 2020
@bkendall bkendall deleted the ss-debugging-improvements branch August 4, 2021 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Manual indication that this has passed CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change timeout behavior when Functions emulator running in debug mode Implement breakpoint debugging in the functions:shell command
4 participants