Bug 109085 - LO exits abruptly when logging off in Windows while LO is running (needs to run SessionSave)
Summary: LO exits abruptly when logging off in Windows while LO is running (needs to r...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: framework (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:6.2.0 target:6.3.0 target:6.2.1
Keywords:
: 117952 (view as bug list)
Depends on: 118573
Blocks: Exit
  Show dependency treegraph
 
Reported: 2017-07-12 15:45 UTC by Aron Budea
Modified: 2023-10-13 12:19 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aron Budea 2017-07-12 15:45:22 UTC
In Windows, log off with a LibreOffice instance running (with a file or at least an empty document open).
After logging back in, start LO again.

=> LO opens with recovery dialog, meaning it didn't exit properly.
Alternatively, before starting LO look in the user profile directory, and note the lock file (named ".lock") there, implying the same.

While it's true Windows forcibly shuts down applications refusing to exit after a while when ending a user session, LO closes right away, but not cleanly. We should make an attempt at shutting down properly.

Observed using LO 5.4.0.1 / Windows 7.

Likely relevant:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa376890(v=vs.85).aspx
http://opengrok.libreoffice.org/xref/core/vcl/win/window/salframe.cxx#5705
Comment 1 Aron Budea 2017-07-12 16:18:32 UTC
Note: don't make any changes to the document during repro, in that case there is a save dialog and LO exits fine after making a choice, but if it's an empty/unchanged document, the shutdown process is not proper.
Comment 2 V Stuart Foote 2017-07-12 21:57:07 UTC
Hmm, maybe related to bug 108299 with zombie soffice.bin/.exe when OpenGL enabled?

Does it behave without OpenGL?
Comment 3 Xisco Faulí 2017-07-13 08:22:51 UTC
Patch in gerrit: https://gerrit.libreoffice.org/#/c/39884/
Comment 4 Aron Budea 2017-07-13 23:16:12 UTC
Stuart, it's not OpenGL related, happens with default rendering as well.

I need to correct my comment 1, it happens if there's a save dialog as well, but in both cases not all the time. However, most of the time LO doesn't exit cleanly.

Collecing the relevant details on Windows messages/behavior here:
https://blogs.msdn.microsoft.com/oldnewthing/20080421-00/?p=22663
https://msdn.microsoft.com/en-us/library/windows/desktop/aa376890
https://msdn.microsoft.com/en-us/library/windows/desktop/aa376889
Comment 5 Mike Kaganski 2017-07-14 06:07:35 UTC
Proposed sketch of solution:

1. Add a handler of WM_ENDSESSION to soffice.bin. Don't handle WM_ENDSESSION there - so by default, this process will simply allow termination.
2. Set its process shutdown level to some high value (0x3FF) to receive this message first (see SetProcessShutdownParameters: https://msdn.microsoft.com/en-us/library/ms686227).
3. Set soffice.bin's process shutdown level to a low value (e.g. to 0x100) to ensure that it doesn't get the notification before soffice.exe finished handling its own WM_ENDSESSION.
4. Handle WM_QUERYENDSESSION in soffice.bin, so that if user has unsaved work, a save query is shown, and if user decided to cancel, then WM_QUERYENDSESSION returns FALSE -> shutdown is terminated. If WM_QUERYENDSESSION returns true, then soffice.bin continues shutdown here, not waiting any other messages.
5. When soffice.exe receives WM_ENDSESSION with wParam = 1, it means that all programs accepted the shutdown in WM_QUERYENDSESSION (including soffice.bin), so we know that soffice.bin is already terminating, and haven't yet received its WM_ENDSESSION (because of shutdown level) -> just wait in the WM_ENDSESSION handler until soffice.bin is finished, and then return. Possibly send an additional shutdown signal to soffice.bin to make sure.

I hope this sequence could help resolving this issue.
Comment 6 Mike Kaganski 2017-07-14 06:37:44 UTC
Correction to #1 in comment 5:

Don't handle WM_ENDSESSION there -> Don't handle WM_QUERYENDSESSION there
Comment 7 Mike Kaganski 2017-07-14 06:38:57 UTC
And another correction to the same #1: it tells about soffice.exe, not about soffice.bin.

Sorry for noise.
Comment 9 Xisco Faulí 2017-11-27 10:03:27 UTC
Dear Mike Kaganski,
This bug has been in ASSIGNED status for more than 3 months without any
activity. Resetting it to NEW.
Please assigned it back to yourself if you're still working on this.
Comment 10 Mike Kaganski 2018-06-01 10:03:35 UTC
*** Bug 117952 has been marked as a duplicate of this bug. ***
Comment 11 Aron Budea 2018-11-04 23:40:35 UTC
I saw Oliver Brinzing's comment in bug 118573 comment 21 on how to simulate shutdown:

rmlogotest.exe (C:\Program Files (x86)\Windows Kits\10\App Certification Kit)

https://superuser.com/questions/959364/on-windows-how-can-i-gracefully-ask-a-running-program-to-terminate#1154058

- start "quickstart.exe"
- get "soffice.bin" PID form taskmanager 
- rmlogotest.exe <pid>
- crash

------

As far as I can see, in Windows 7 using the following command has the same effect:
taskkill /f /pid <pid>
Comment 12 Aron Budea 2018-11-04 23:58:10 UTC
(In reply to Aron Budea from comment #11)
> As far as I can see, in Windows 7 using the following command has the same
> effect:
> taskkill /f /pid <pid>
I'm uncertain whether this is really useful here, whether it's the same procedure as logging off, or whether it simply kills the process... could be the latter.
Comment 13 Mike Kaganski 2018-11-05 10:02:17 UTC
https://gerrit.libreoffice.org/62881
Comment 14 Commit Notification 2018-11-05 14:11:00 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/+/3d8c159841bcab7365b2bed3df71ed3c15188312%5E%21

tdf#109085: don't assume MtaOleReq window is still valid at shutdown

It will be available in 6.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 15 Xisco Faulí 2018-12-06 13:19:24 UTC Comment hidden (obsolete)
Comment 16 Aron Budea 2018-12-14 09:12:52 UTC
(In reply to Xisco Faulí from comment #15)
> Is this bug fixed? if so, could you please close it as RESOLVED FIXED ?
> Otherwise, Could you please explain what's missing?
The original issue still persists (tested with a build from yesterday, 18-12-13). It's not obvious what needs to be fixed for this to work, so unless the issue is gone after a similar fix, or there is a new discovery, we don't know what's still missing.
Comment 17 Commit Notification 2019-02-05 09:10:52 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/+/11a2809e369b2a6fcbb2d7f0db131a945557c6e2%5E%21

tdf#122435: reimplement fix for tdf#109085

It will be available in 6.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 18 Commit Notification 2019-02-08 14:46:44 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-6-2":

https://git.libreoffice.org/core/+/9d7baded9f315096f247af15a23fd899fc4facc3%5E%21

tdf#122435: reimplement fix for tdf#109085

It will be available in 6.2.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 19 Xisco Faulí 2019-03-13 18:37:07 UTC
@Aron Budea,
is this issue still reproducible after Mike's patches ?
Comment 20 Aron Budea 2019-03-13 21:22:42 UTC
Yes, tested again with LO 6.3.0.0.alpha0+ (x64) (4f810905fa74128871f2fe924a3d28a79f4e4261) / Windows 7.
I had to repeat it 3-4 times, but got a .lock file remaining, indicating LO didn't shut down cleanly.
Comment 21 QA Administrators 2021-03-13 04:08:50 UTC Comment hidden (spam)