Skip to content

[io] Prevent losing data due to SIGTERM (under Unix)#18403

Open
ferdymercury wants to merge 2 commits intoroot-project:masterfrom
ferdymercury:sigterm
Open

[io] Prevent losing data due to SIGTERM (under Unix)#18403
ferdymercury wants to merge 2 commits intoroot-project:masterfrom
ferdymercury:sigterm

Conversation

@ferdymercury
Copy link
Collaborator

@ferdymercury ferdymercury commented Apr 14, 2025

This Pull request:

Changes or fixes:

Fixes #13300

  • I tested this locally on Ubu22 and it works fine.
  • I do not know how to properly test it using GTEST, I only found test_polling.cxx doing something like that but it looked too complicated, so I ended up simplifying.
  • I do not know if Windows must catch SIGTERM somewhere else @bellenot ?

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

@github-actions
Copy link

github-actions bot commented Apr 14, 2025

Test Results

    22 files      22 suites   3d 18h 35m 56s ⏱️
 3 707 tests  3 660 ✅ 0 💤 47 ❌
79 603 runs  79 509 ✅ 0 💤 94 ❌

For more details on these failures, see this check.

Results for commit 64374c4.

♻️ This comment has been updated with latest results.

@bellenot
Copy link
Member

@ferdymercury The SIGILL and SIGTERM signals aren't generated under Windows. They're included for ANSI compatibility. See the signal reference

@ferdymercury ferdymercury changed the title [io] Prevent losing data due to SIGTERM [io] Prevent losing data due to SIGTERM (under Unix) Apr 22, 2025
@ferdymercury ferdymercury added this to the 6.38.00 milestone Apr 22, 2025
@bellenot bellenot assigned dpiparo and pcanal and unassigned bellenot Apr 25, 2025
@dpiparo dpiparo closed this May 23, 2025
@dpiparo dpiparo reopened this May 23, 2025
@dpiparo
Copy link
Member

dpiparo commented May 23, 2025

Let's have a look to the tests once again

Comment on lines +109 to +110
// gentle save and close if SIGTERM
if (signum == SIGTERM) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, this would mean that after code similar to:

root [] TFile f(filename, RECREATE);
root [] do_stuff();
root [] if (all_is_well) f.Write();

We have a different behavior if the user does:

root [] .q

and

send SIGTERM

Where the former does not write the file while the later would now write the file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I tried to explain here, #13300 (comment), I think this is a logical behaviour. The prompt experience does not change. The behaviour if SIGKILL is used does not change. However, if SIGTERM is used, some kind of "soft termination" that gives the process a way to wrap up and end gracefully, is the right thing to do.

Copy link
Collaborator Author

@ferdymercury ferdymercury Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create a ".wq" ROOT command (one char longer than ".q") to do the equivalent of save and exit as if it were vim, if one wants to rely on this without having to look how to send SIGTERM. Or just for symmetry with SIGNALS.

@ferdymercury ferdymercury force-pushed the sigterm branch 2 times, most recently from f6f707e to 4f28265 Compare May 25, 2025 16:31
@ferdymercury ferdymercury reopened this May 25, 2025
@ferdymercury ferdymercury added the clean build Ask CI to do non-incremental build on PR label May 25, 2025
@ferdymercury ferdymercury reopened this May 25, 2025
@ferdymercury ferdymercury removed the clean build Ask CI to do non-incremental build on PR label May 25, 2025
@dpiparo dpiparo closed this Jun 2, 2025
@dpiparo dpiparo reopened this Jun 2, 2025
@ferdymercury ferdymercury force-pushed the sigterm branch 2 times, most recently from 571cd12 to beb694c Compare June 21, 2025 13:24
@ferdymercury ferdymercury modified the milestones: 6.38.00, 6.40.00 Dec 2, 2025
@dpiparo
Copy link
Member

dpiparo commented Mar 4, 2026

I would be in favour of approving, @pcanal , but only if you also agree with the point I made above.

Fixes root-project#13300

[core] Implement public static functions allowing save and close

[io] only SaveAndClose TFiles and derived

TSystemFile, in general, does not implemente Write and Close methods

[io] Do not write/close files open in READ mode

[core] use TDirectory instead TMethodCall
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.

Test SIGTERM vs ~TFile

4 participants