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: remove process signals handling #1

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

g11tech
Copy link

@g11tech g11tech commented Mar 30, 2023

Remove the hardcoded signal processing as lodestar the main user of this library terminates thread explicitly

See

@nflaig
Copy link
Member

nflaig commented Mar 30, 2023

@g11tech what are the changes required in Lodestar to make this work? I looked at it yesterday but didn't get it to properly close all workers, might be that I missed something

@g11tech
Copy link
Author

g11tech commented Mar 30, 2023

i think process.exit will still need to be called after full node.close as i have no idea why the main thread would still remain hanging even though we terminate all workers in lodestar.

even this package still calls process.exit after terminating, so there is some reason exit needs to be called.

@wemeetagain
Copy link
Member

We should debug why we still need an explicit process.exit (even if we add a process.exit in the short term to resolve the issue).
Its likely that stray event listeners are still attached.

@wemeetagain wemeetagain merged commit bcfc28c into master Mar 30, 2023
@wemeetagain wemeetagain deleted the g11tech/remove-signal-handling branch March 30, 2023 17:41
@nflaig
Copy link
Member

nflaig commented Mar 30, 2023

It does look like Lodestar actually depends on this package to exit the process.
As far as I understand adding a signal listener suppresses the default signal handling behavior which is what we are doing here https://github.com/ChainSafe/lodestar/blob/a2f749a6f08d5b8f6d1c52147b08f71d48f7abe2/packages/cli/src/util/process.ts#L15.

Don't we have to call process.exit(0) after cleanUpFunction is done?

@g11tech
Copy link
Author

g11tech commented Mar 30, 2023

if there are no pending things to execute, the program should shut down (i think)

@nflaig
Copy link
Member

nflaig commented Mar 30, 2023

I am not sure we can make sure there is no pending things to execute, a simple missed interval or timeout will keep the process alive

process.on("SIGINT", () => {
  console.log("Caught SIGINT!");
});

setInterval(() + {
  console.log("Still alive!");
}, 1000);

This process will not exit if you do Ctrl + C

Still alive!
Still alive!
^CCaught SIGINT!
Still alive!
Still alive!
Still alive!
^CCaught SIGINT!
^CCaught SIGINT!
Still alive!
Still alive!

I checked a bunch of libraries and they seem to explicity call process.exit

something like this from https://github.com/open-telemetry/opentelemetry-js#set-up-tracing

process.on('SIGTERM', () => {
  sdk.shutdown()
    .then(() => console.log('Tracing terminated'))
    .catch((error) => console.log('Error terminating tracing', error))
    .finally(() => process.exit(0));
});

@wemeetagain
Copy link
Member

a simple missed interval or timeout will keep the process alive

Ideally a proper cleanup would close every timer. Not easy but 🤷

We can add a process.exit call in our cli since you tested and verified we need it.

@nflaig
Copy link
Member

nflaig commented Apr 1, 2023

Ideally a proper cleanup would close every timer. Not easy but 🤷

Agreed...started attempt in ChainSafe/lodestar#5330

We can add a process.exit call in our cli since you tested and verified we need it.

Should clean this up as much as possible and find all active handlers which keep the process running. Once this is done I would still just call process.exit(0) or process.exit(1) on error, I think it is not such a bad thing to do and having a hanging process sounds annoying for users

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