Closed Bug 1837907 Opened 2 years ago Closed 2 years ago

Not handle system shutdown (SIGTERM)

Categories

(Core :: Widget: Gtk, defect, P2)

Firefox 116
defect

Tracking

()

RESOLVED FIXED
122 Branch
Tracking Status
firefox122 --- fixed

People

(Reporter: vip4444, Assigned: stransky)

References

Details

Attachments

(2 files, 2 obsolete files)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0

Steps to reproduce:

I shutdown my system by /sbin/poweroff (/sbin/reboot) or by dbus command "dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.PowerOff" boolean:true", but after next run system FireFox starting as after crash, not as after correct shutdown. If I close FF by "Close" button on program caption or by command "File->Exit" in menu - all Ok.

Actual results:

Not handle system shutdown.

Expected results:

Handle system shutdown.

The Bugbug bot thinks this bug should belong to the 'Core::Printing: Output' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Printing: Output
Product: Firefox → Core

Also bug occur when "killall firefox" and not occur when close by "wmctrl -c 'Firefox'".

The severity field is not set for this bug.
:emilio, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(emilio)

Well you're killing Firefox, maybe we could do something more graceful for SIGTERM or use some sort of shutdown blocker and wait for clean shutdown? But not sure how much of a rabbit-hole that would be.

Component: Printing: Output → Widget: Gtk
Flags: needinfo?(emilio)
Priority: -- → P3

Based on comment 4 change status to "New".

Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(stransky)

Alexander, do you mind to try to create a patch for it? a mini-howto can be found here:
https://mastransky.wordpress.com/2023/07/04/no-one-fights-alone-a-guide-to-your-first-firefox-patch-on-linux/
Thanks.

I do not have ready solution for make patch.
This is requiring research.
https://stackoverflow.com/questions/22009705/how-to-detect-linux-shutdown-reboot
Only signal handling is not enough to solve this problem.
I have handled signals in my program, but it work only for Ctrl+C situation, not for shutdown system.
https://github.com/galaxysite/gorg64_spkplay/blob/main/gorg64_spkplay.pas
May be this problem already resolved in Falkon ?
https://github.com/KDE/falkon
Outwardly it looks like this.
Also I do not have ready solution for dbus.

You can handle the DBus message 'org.freedesktop.login1.Manager.PowerOff'. Not sure if it's even possible to catch /sbin/poweroff and if that sends any signal to application.

IIUC Windows try to catch SIGTERM here:
https://searchfox.org/mozilla-central/rev/d81e60336d9f498ad3985491dc17c2b77969ade4/widget/windows/nsWindow.cpp#4936
(or something which matches SIGTERM on Windows) so can the code be the same on Linux and may it be executed in SIGTERM handler?

Looks like poweroff directly uses reboot kernel call (https://man7.org/linux/man-pages/man2/reboot.2.html) and it's kind of emergency shutdown. I doubt any desktop application/environment can handle this kind of shutdown seamlessly.

Not-not, poweroff is not emergency. This is the standard, non-emergency way for shutdown of a System. poweroff/reboot - command for change runlevel of System: https://www.geeksforgeeks.org/run-levels-linux/ All other ways more modern: poweroff/reboot historical, standard way of shutdown.

SIGTERM on Windows
Only process messages. Signals are not exactly messages.
In the old days, I solved this problem like this:
...

procedure OnQEnd(Var Msg : TMessage); message WM_QUERYENDSESSION;
procedure OnEnd(Var Msg : TMessage); message WM_ENDSESSION;
procedure OnSysCommand(Var Msg: TWMSysCommand); message WM_SYSCOMMAND;

...

procedure MyMain.OnSysCommand(Var Msg: TWMSysCommand);
begin
if msg.CmdType = SC_CLOSE then begin
if MessageBox(hwnd, PCHar(app_quit), PCHar(app_name), bit6 or bit3) <> ID_YES then begin msg.Result := 0; exit; end;
end;
msg.Result := DefWindowProc(hwnd, msg.msg, TMessage(msg).WParam, TMessage(msg).LParam);
end;

procedure MyMain.OnQEnd(Var Msg : TMessage);
begin
app.terminated := true;
msg.Result := Longint(true);
end;
procedure MyMain.OnEnd(Var Msg : TMessage);
begin
while app.terminated do sleep(0); // during the shutdown of the program and saving its files in 2-st thread
msg.Result := 0;
end;

I quest about this systemd creators and get answer:

https://github.com/systemd/systemd/issues/29146
We emit PrepareForShutdown dbus signal before/after initiating the shutdown process: https://www.freedesktop.org/software/systemd/man/org.freedesktop.login1.html#Signals

Summary: Not handle system shutdown → Not handle system shutdown (SIGTERM)
Flags: needinfo?(stransky)
Priority: P3 → P2
Flags: needinfo?(stransky)
Flags: needinfo?(stransky)

We want to handle SIGTERM gracefully and terminate Firefox by standard way.

Assignee: nobody → stransky
Status: NEW → ASSIGNED

SIGTERM is supposed to be a standard way how to terminate Linux application. So don't fire emergency exit but run usual exit sequence.

Depends on D191077

Pushed by stransky@redhat.com: https://hg.mozilla.org/integration/autoland/rev/a78b3fba98aa [Linux] Don't catch SIGTERM in nsProfileLock r=jld https://hg.mozilla.org/integration/autoland/rev/ff3a75dbd146 [Linux] Catch SIGTERM in nsAppShell and terminate Firefox by standard way r=jld

Backed out for causing xpcshell failures in marSuccessPartialWhileBackgroundTaskRunning.js.

L.E. There are also these Mn failures.

Flags: needinfo?(stransky)

Install SIGTERM handler only if we use event loop. That keeps default SIGTERM handler for applications without event loop like xpcshell.

Depends on D191079

Flags: needinfo?(stransky)
Pushed by stransky@redhat.com: https://hg.mozilla.org/integration/autoland/rev/7a2134520f7c [Linux] Don't catch SIGTERM in nsProfileLock r=jld https://hg.mozilla.org/integration/autoland/rev/a883cbc99803 [Linux] Catch SIGTERM in nsAppShell and terminate Firefox by standard way r=jld https://hg.mozilla.org/integration/autoland/rev/28174e34160b [Linux] Install SIGTERM handler from ProcessNextNativeEvent() r=emilio
Flags: needinfo?(stransky)
See Also: → 336193

Surprisingly event loop is also called on xpcshell but when it's terminated. So we need to use something different here.

Attachment #9362304 - Attachment is obsolete: true
Flags: needinfo?(stransky)
Pushed by stransky@redhat.com: https://hg.mozilla.org/integration/autoland/rev/e1d41d593702 [Linux] Don't catch SIGTERM in nsProfileLock r=jld https://hg.mozilla.org/integration/autoland/rev/8502ba0bf6a6 [Linux] Catch SIGTERM in nsAppShell and terminate Firefox by standard way r=jld https://hg.mozilla.org/integration/autoland/rev/89b150d0c0ab [Linux] Disable AppShell SIGTERM signal handler for xpcshell r=emilio
Attachment #9358612 - Attachment is obsolete: true
Attachment #9364663 - Attachment description: Bug 1837907 [Linux] Disable AppShell SIGTERM signal handler for xpcshell r?emilio → Bug 1837907 [Linux] Enable AppShell SIGTERM signal handler for Firefox r?emilio
Pushed by stransky@redhat.com: https://hg.mozilla.org/integration/autoland/rev/f7551ea88778 [Linux] Catch SIGTERM in nsAppShell and terminate Firefox by standard way r=jld https://hg.mozilla.org/integration/autoland/rev/1035a42c6a86 [Linux] Enable AppShell SIGTERM signal handler for Firefox r=emilio

Backed out for causing xpcshell failures in marSuccessPartialWhileBackgroundTaskRunning.js

  • Backout link
  • Push with failures
  • Failure Log
  • Failure line: TEST-UNEXPECTED-FAIL | toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartialWhileBackgroundTaskRunning.js | run_test - [run_test : 115] -15 == -9

And also marionette failures: https://treeherder.mozilla.org/jobs?repo=autoland&group_state=expanded&searchStr=linux%2C18.04%2Cx64%2Cwebrender%2Cdebug%2Ctest-linux1804-64-qr%2Fdebug-marionette-swr%2Cmn-swr&revision=1035a42c6a86393419461fd90d38c7fa183b92f3&selectedTaskRun=YB-XIBOKS9-5VDMu3MCKzA.0

Pushed by stransky@redhat.com: https://hg.mozilla.org/integration/autoland/rev/7fe397f45f7b [Linux] Catch SIGTERM in nsAppShell and terminate Firefox by standard way r=jld https://hg.mozilla.org/integration/autoland/rev/f5150abdafbd [Linux] Enable AppShell SIGTERM signal handler for Firefox r=emilio
Flags: needinfo?(stransky)
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 122 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: