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

Inspect mode conflicts with separate processes mode #508

Closed
ukrbublik opened this issue Oct 20, 2018 · 8 comments
Closed

Inspect mode conflicts with separate processes mode #508

ukrbublik opened this issue Oct 20, 2018 · 8 comments

Comments

@ukrbublik
Copy link

ukrbublik commented Oct 20, 2018

This will not work:
node --inspect ./node_modules/serverless/bin/serverless offline --useSeparateProcesses start
Child processes will exit with code 12.
It's because they will try to share same arguments with parent sls process.

This is dirty workaround:

      const ipcProcess = fork(helperPath, [funOptions.handlerPath], {
        env: _.omitBy(process.env, _.isUndefined),
        stdio: [0, 1, 2, 'ipc'],
        execArgv: process.execArgv.filter(a => a != '--inspect')
      });

at functionHelper.js

@dherault
Copy link
Owner

noted, thanks.

@andrewc89
Copy link

I am running into this issue as well. When I run:

node --inspect ./node_modules/.bin/sls offline start --useSeparateProcesses --noAuth --stage dev --port 5000

without the changes to functionHelper.js, I get the following output:

Serverless: The first request might take a few extra seconds
Starting inspector on 127.0.0.1:9229 failed: address already in use
Serverless: Failure: Handler process exited with code 12
Serverless: Replying 200

If I remove the --useSeparateProcesses argument, everything works, including debugging. Initially I only see the node_modules in the debugger, but after hitting an endpoint, my code files are shown (which is documented in the README).

However, we are using Inversify and need to use the --useSeparateProcesses command. So after I make the changes to functionHelper.js, everything works as expected except that I don't ever get my code files loaded into the debugger.

@ukrbublik did you find a way to get your code to show up in the debugger?

I also think that when the process exits with code 12, shouldn't it reply with a 500? The 200 reply is confusing.

@ukrbublik
Copy link
Author

ukrbublik commented Dec 5, 2018

@gwely

@ukrbublik did you find a way to get your code to show up in the debugger?

No.
Separate processes should use another ports for inspector (not 9229, but 9230, 9231..), it's a problem

@rdsedmundo
Copy link

I'm running in the same problem.

And I came up in the exact same conclusion:

It's because they will try to share same arguments with parent sls process.

@dherault why did you close this issue? Is this already work in progress?

@dherault dherault reopened this Feb 8, 2019
@dherault
Copy link
Owner

dherault commented Feb 8, 2019

Because of the workaround given. But let's re-open it.

@rdsedmundo
Copy link

I think his workaround was mentioning editing the plugin at this LOC: https://github.com/dherault/serverless-offline/blob/master/src/functionHelper.js#L116

@Can-Sahin
Copy link

Can-Sahin commented May 14, 2019

Same issue here!

I'm using NestJS with typeorm and there is singleton issue with connections of typeorm. So i use the flag --useSeparateProcesses and it works. But this time debug launch fails with address already in use error. Same with @gwely

I have to use this flag for local development otherwise its a nightmare but now debug won't work.

What to do ? 😕

UPDATE: I don't know which update made it possible but you can name the connections with TypeOrmModule.forRootAsync({}) something random everytime and my problem disappears for running locally

@dnalborczyk
Copy link
Collaborator

dnalborczyk commented Sep 12, 2019

for the purpose of debugging one should run serverless-offline in-process (not as a separate process). it might be also possible to debug child processes with ndb. I have not tried that myself yet.

that being said, in v6 we introduced running the handlers in worker threads (--useWorkerThreads option if your node.js version allows this, v11.7+ is required) and this is also recommended, and will likely be the default in future versions of this plugin.

unfortunately debugging worker threads with chrome dev tools is not yet possible as well (nodejs/node#26609), but should also be supported with ndb (GoogleChromeLabs/ndb#277)

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

No branches or pull requests

6 participants