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

Clean up on Deno.exit() #3603

Closed
phil294 opened this issue Jan 5, 2020 · 5 comments · Fixed by #9088
Closed

Clean up on Deno.exit() #3603

phil294 opened this issue Jan 5, 2020 · 5 comments · Fixed by #9088
Labels

Comments

@phil294
Copy link

phil294 commented Jan 5, 2020

window.onunload and window.addEventListener "unload" work fine for when a script normally ends. But when

  • an uncaught exception is thrown
  • Deno.exit() is called
  • (process is stopped, e.g. SIGINT - should be fixed with Signal Handlers #2339)

it seems, there is no way to do any clean up action. Is this intended?

Thanks and much love to all contributors.

@kevinkassimo
Copy link
Contributor

IMO we should treat these 3 scenarios as different "emergency exits", and they each might have independent implications. It might be better to treat them independently:

  • uncaught exception could have its own listener, like that of process.on("uncaughtException", ...) in Node.js, allowing getting a handle to the error.
  • Might be reasonable to have Deno.exit() or SIGINT invoke onunload that unlistens itself when starting running.

@hayd
Copy link
Contributor

hayd commented Jan 18, 2020

Related: it'd be nice to configurably change exit's behavior to throw.
(This is a problem for deno-lambda.)

@marcosc90
Copy link
Contributor

This causes FileHandler from std/log to miss logs if you send a SIGINT.

@ahuggins-nhs
Copy link

ahuggins-nhs commented Sep 4, 2020

Can confirm this is still an issue. Not sure where in the code to look yet as far as what can be done to fix.

Similar pattern on Node "just works":

process.on('exit', () => console.log('Hello, world!'))
process.exit() // Console outputs "Hello, world!".

Equivalent in Deno just does... nothing?

window.onunload = () => console.log('Hello, world!')
Deno.exit() // Nothing to see here, move along...

EDIT:
It is somewhat possible to work around this for intentional exits. I'm adding something like the following to a library I'm working on for mocha in deno:

    try {
      window.dispatchEvent(new Event('unload'))
    } catch (error) {}
    Deno.exit(1)

Does not take care of anything unintended by a library author or signal interrupts from the user/os. But it's a workaround.

@stale
Copy link

stale bot commented Jan 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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 a pull request may close this issue.

5 participants