`deno run` not returning
Hi - I have added the following code to my javascript file, and for some reason the code still executes fine, but it doesn't return anymore, leaving deno running and I have to
ctrl-c
out of it.
This prints out the setup paper
. I have added some prints surrounding my entry point main, and those all print as well:
So what could be keeping the deno
instance from returning/finishing?17 Replies
Based on the code snippets you've provided, it seems like your Deno program is not exiting because there might be some unresolved promises or ongoing asynchronous operations that are preventing the event loop from becoming empty, which is a requirement for the program to exit naturally.
In the first snippet, you're dynamically importing modules and setting up
paper
. If paper.setup()
initiates some asynchronous operations that do not resolve or if there are event listeners that are still active, Deno will not exit as it waits for all asynchronous operations to complete.
In the second snippet, you're using a try...catch...finally
block to execute main()
and then wait for all asynchronous operations to complete with a setTimeout
. However, the setTimeout
in the finally
block is unnecessary if you want the program to exit after main()
has completed, as it introduces an additional asynchronous operation into the event loop.
Here are a few steps you can take to debug this issue:
1. Check for Active Timers or Intervals: Ensure that there are no active setTimeout
or setInterval
calls that are keeping the event loop busy. If you have any, make sure to clear them with clearTimeout
or clearInterval
once they are no longer needed.
2. Check for Active Listeners: If you have set up any event listeners (like paper.on('event', handler)
), ensure that they are removed when they are no longer needed.
3. Check for Unresolved Promises: If there are promises in your code (or in the libraries you are using) that are not resolving, they can keep the event loop active. Make sure all promises are either resolved or rejected.
4. Use Deno's Diagnostic Tools: Deno provides diagnostic commands like deno info
that can help you understand the moduledependencies and possibly identify where the issue might be occurring.
5. Simplify Your Code: Try to simplify your code to the smallest version that reproduces the issue. This can often help pinpoint the exact cause.
6. Review Third-Party Modules: Since you are importing third-party modules, it's possible that they may have some cleanup code that needs to be run or they may be starting some background tasks that need to be stopped.
If after reviewing these areas you still cannot find the cause, you may need to add more logging to your code to trace the execution flow and identify where the program is getting stuck. Remember that Deno will not exit if there are unresolved promises, active timers, or event listeners that are still being watched in the event loop. 🦕
Helpful Links:
Deno 1.29: Custom npm registry support
Deno 1.21 Release Notes
Deno 1.19 Release Notes
Deno 1.36: More flexible security and expanded testing APIs
Deno 1.24 Release Notes
Migrating from Node.js to Deno | Deno Docs
Build a Cross-Platform CLI with Deno in 5 minutes
deno repl, interactive scripting prompt - Deno Docs
deno task | Deno Docs
It seems to be something with the Node.js compat layer
eventLoopTick()
function. I don't encounter this when using the same code in the browser, but I also don't really know whether there are any remaining unresolved promises there, but I'm not constructing any. Now investigating whether this library does that
Hmm, with the chromium debugger I don't really see how to get past this. The paper
and paper-jsdom
node modules seem to have been replaced by symlinks as well. Going to reinstall those
Yeah, even without the npm
specifiers in the import, the call stack gets highjacked by node:timers
setInterval()
function@Auke That sounds like a bug in Deno. Can you file an issue here with the steps to reproduce it? https://github.com/denoland/deno/issues/new/choose
I will try to get an mre going
The snippet you provided here sounds fine if that's enough to reproduce it 🙂
Yeah, will have to figure out if that is enough! But looks like it, I've reduced it to one library call that is causing this to hang
Could you evaluate whether this also hangs on your side?
https://github.com/aukeroorda/mre-deno-hang
GitHub
GitHub - aukeroorda/mre-deno-hang
Contribute to aukeroorda/mre-deno-hang development by creating an account on GitHub.
If it does, Ill create an issue on the repo!
I've added a second method of importing the library, and that also causes the hang. Going to create the issue
GitHub
Deno hangs after succesfully executing npm-package library call · I...
deno --version deno 1.41.3 (release, x86_64-apple-darwin) v8 12.3.219.9 typescript 5.3.3 MRE Can be found at: https://github.com/aukeroorda/mre-deno-hang/tree/main Verify the contents of the r...
It is a blocker for my thesis, so would love to find a solution to this! In the worst case I will just have to run this using Node I guess, but that would be some rewriting
Thanks for creating an issue! It hangs for me too when running the steps. Something is wrong in Deno.
Is that package using native add-ons?
I'm not familiar with the term 'native add-ons'
@bartlomieju I don't think so. From what I understand, they are non-js language addons; In the repository of this library I see just js+ts: https://github.com/paperjs/paper.js
GitHub
GitHub - paperjs/paper.js: The Swiss Army Knife of Vector Graphics ...
The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey - paperjs/paper.js
Interesting I wonder if it might have problems because Deno has
window
global and the library thinks it's in the browser
Can you try again with DENO_FUTURE=1
env var?Ah, please reply on the github issue, as I don't visit discord often
Will have a look
Changing window to
globalThis
causes it to run again, but also hang again, with DENO_FUTURE=1
@bartlomieju