-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Deno.exit terminates entire process when using run --watch #7590
Comments
Keep the file watcher alive to do what? |
I thought Deno would continue to check for file changes, even after my script calls let someErrorCondition = true;
if (someErrorCondition) {
console.log('Exiting');
Deno.exit(1);
}
console.log('Finished');
I expected to see the "Process terminated! Restarting on file change..." message after my script logged "Exiting", so I could make some changes to the script, and the script would re-run. |
If you exit your programme, you exit your program. I personally would find it surprising that if my programme has exited, that it suddenly restarts. Like a "watch" in a browser, if the code changes and the page is still open, it reloads. If you close the page, you close the page. Anything else would be surprising in my opinion. |
I see, I thought my use case was the most common. This is totally possible to solve in userland, so I can use some other tool to get quick feedback while developing. I was surprised because tools in other environments continue to watch for files after their corresponding "exit" method is called, like |
I agree that this is pretty unexpected - when the program exits by natural means (no more tasks to do), it also restarts when the file changes. I think that should also apply to |
May I work on this issue? |
I agree with @lucacasonato and I think this is a reasonable feature to implement. If anyone wants to work on this feature I'll be happy to provide guidance on how to handle that, but long story short, we should override |
I'd like to work on this but I could use some pointers :) |
@jespertheend I'm going to work on #12938 this week, which will require similar effort to this issue. I'll add pointers on how to tackle this issue after finishing my PR. |
@jespertheend sorry for late response. I did some experiments in #12938 and although I have some idea how we could tackle this issue, it's definitely on the "very hard" spectrum of the problem; so I'm not sure I can provide pointers on how to implement that. I will be tackling #13093 in this quarter, after that issues is addressed fixing this issue will be much more approachable. |
That's alright, I think it's better to wait then. I only wanted to work on this to get a better understanding of Rust so it's not a priority for me. |
It seems like in this case deno should create a child process with the exact same arguments sans If the parent process receives any signals, it should forward them to the child process and once the child exits the main process should exit. |
Is there a way to detect that deno is running in watch mode? It would be a helpful workaround, I could just not call deno.exit in that case. |
Unfortunately there is no way to tell that. I'll try to make time to fix this issue this week. |
@justinmchase opened #14787 |
Is #14787 still the PR that will effectively resolve this issue? If it's reopened and merged of course :) |
Possibly, but I haven't found a reliable way to handle |
Relating to #14787 (comment) I recently had to whip up a quick test harness and part of that harness were some pre-checks which I wanted to abort on if they failed, so Using a task and Here's my implementation in-situ but also summarised inline below:
|
I just found this thread while dealing with a different issue. For me, the current behaviour of TL;DRCalling Long versionHere is a real example, where I encountered this issue. // server.ts
const kv = await Deno.openKv("./db.sqlite");
const server = Deno.serve(async () => {
await kv.atomic().sum(["visitor_count"], 1n).commit();
const { value } = await kv.get(["visitor_count"]);
return new Response(`Hello world! You are the ${value}th visitor.`, { status: 200 });
}); I built an HTTP server with // server.ts continuation
Deno.addSignalListener("SIGINT", async () => {
kv.close();
await server.shutdown();
}); This performs a clean KV shutdown when I press CTRL-C, and leaves no KV temp files behind on my hard drive. However, once I run this with |
@pschiffmann That makes sense. It seems almost like it would be beneficial for the signal listener to continue on with its normal behavior after the callback function is finished executing. Your function is async, if the returned promise was awaited inside the Deno runtime and then continued on with handling SIGINT as normal then that would allow the user to override the behavior still by just not returning and also in your case what you want is for the normal Ctrl+C behavior to happen after you're done shutting down but without having to call exit. Because it seems like the cruxt of the problem in this case is that when Ctrl+C signal is sent to the Deno process the intent is for everything to shutdown but when a |
@justinmchase Full disclosure, I'm not super educated on OS processes, like what idiomatic or spec compliant signal handling behaviour looks like. I'm coming to deno from a web/JS background. So I don't have an opinion on how this API should work. I just encountered an edge case that I didn't see mentioned here, and thought I'd bring it up. :-) |
I'm running my script with
deno run --watch --unstable myscript.ts
. When it encounters a call toDeno.exit
, the script terminates, including the file watcher.I expected
Deno.exit
to terminate the script, but keep the file watcher alive. This is how Node'sprocess.exit
behaves when used with nodemon.It seems culprit is the current implementation, which is just a passthrough to
std::process::exit
. I'm still familiarizing myself with Deno and V8, but is the solution something like tearing down the active runtime without exiting the main process?The text was updated successfully, but these errors were encountered: