-
Notifications
You must be signed in to change notification settings - Fork 391
create project temp in correct directory and clean it up. #12329
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
Conversation
cderv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed the PR - I was deep into something today.
This PR is unfortunately incomplete. We are calling createTempContext twice. The other is there
quarto-cli/src/project/project-context.ts
Lines 361 to 363 in 8bd9c6e
| const temp = createTempContext({ | |
| dir: join(dir, ".quarto", "temp"), | |
| }); |
So same change needs to be done.
Also, we discussed maybe revert back to use globalTempContext instead of this new .quarto/quarto-session-temp<id> so that we may not add more in local project directory of users.
It is a choice. I don't know which you prefer. My take is that filesystem and paths handling is hard and side-effect prone. So creating a new folder locally to project to store everything that was previous in OS temp folder could lead to some side effect. As it seems not required to use this new project context, maybe we should not. IDK.
Using global, means we do
const temp = globalTempContext();
No matter project or singlefile render.
|
Right - let me fix that one too. |
I agree that there are risks, and maybe we'll need to revert it. This PR makes it so that we know exactly when the project temporaries are cleaned up, which wasn't the case with the previous code. Since we have to be careful about it when it comes to open files, I think I prefer this approach. But you're right that we could have done it differently. |
I guess I had the other logic in minds: It feels safe and clear to write temporary stuff (that should be deleted) in the So my mental model was simple: This temporary => it goes into global Temp context => it will be cleaned up before Quarto exists. Anyway, I am not trying to change your mind, just wanted to be sure my understanding weighted in 😄 |
|
I guess one of my concern is what happens when quarto errors out. We encountered previously problem when
Will that be the case with To me using globalTempContext() gives this insurance. New project level temp makes me wonder if we won't miss some cases. Hope this clarify some example I have in mind about this question. Thanks for reading! |
|
This kind of cleaning up should be happening in try..finally clauses, which will work if we have uncaught exceptions. You're right that this is not how all of our cleanup happens. But! Notice how our abnormal termination error handlers happen, they're not called on windows at all: Lines 30 to 33 in 2ed6772
This is because signal handlers are a UNIX-specific feature. So we should be trying extra hard to be doing things on try..finally clauses instead of on |
That was my missing part I guess. Doing in And thanks for the Using AI friend to come up with an example signal_test.ts // signal_test.ts
const abend = () => {
console.log("Received termination signal. Cleaning up...");
// Simulate cleanup logic
setTimeout(() => {
console.log("Cleanup done. Exiting...");
Deno.exit(0); // Exit the process
}, 1000); // Wait for 1 second before exiting
};
// Listen for SIGINT (Ctrl+C)
Deno.addSignalListener("SIGINT", abend);
console.log("Running... Press Ctrl+C to exit.");
// Keep the application running
setInterval(() => {
console.log("Still running...");
}, 2000); // Log every 2 secondsthis gives ❯ deno run signal_test.ts
Running... Press Ctrl+C to exit.
Received termination signal. Cleaning up...
Still running...
Cleanup done. Exiting...So we should probably modify this code right ? |
|
I don't know how Deno's signal handlers work (and what they interpret a signal to mean in Windows... Windows has no unix signals!), but there's very many things you're not supposed to do from inside a signal handler. If I remember my undergrad classes correctly, even printing to stdout is risky and not allowed, because printing might block (if, eg, someone is redirecting stdout to a FIFO). If you block inside an interrupt handler, other bad juju can happen, etc etc. So I would be very reluctant to add to our signal handlers. We should be doing our best to remove code from them instead... |
I trust you on this 💯 ! I may not have understood your previous comment. I thought the code was showing that we currently don't cleanup on interrupt CTRL + C on Windows, while we do on Linux. The only takeaway is that |
(cc @cderv)
We weren't cleaning quarto's temporary directories for projects properly, nor were we creating them where we expected. This fixes both issues.