Recent

Author Topic: Application seems to hang during shutdown?  (Read 666 times)

Fungus

  • Sr. Member
  • ****
  • Posts: 354
Application seems to hang during shutdown?
« on: June 11, 2025, 07:57:54 pm »
I am using Laz from repos (V3.0 / FPC 3.2.2) on Kubuntu 24.04 and I am compiling to Qt5 target. The same issue was also present with an older version of Laz+FPC on Kubuntu 22.04.

I have a background application, which most of the time is minimized to an icon in the system tray / status area. In the application there is a TForm and a TThread is started in FormCreate in order to listen for UDP messages, all works great!

If I click the "cross" (close button) in the top right of the main form / titlebar, the main form events "OnClose" and then "OnDestroy" are triggered as expected and the TThread can be terminated gracefully whereafter the application is terminated in less than a second.

If I shut down the system whilst the application is running in the background, the system hangs for 5-10 seconds before shutting down and neither the main forms "OnClose" nor "OnDestroy" events are triggered, so I am assuming that it is the un-terminated TThread which causes the hang. If I shut down the application by sending "SIGTERM" to it using the application/process list in the system monitor, neither "OnClose" nor "OnDestroy" are triggered and the termination hangs as with system shutdown.

I have tried to use fpSigaction in order to intercept SIGINT and SIGTERM, and from the sigaction handler I am invoking "form.Close()", which causes the "OnClose" event of the main form to trigger immediately, but the "OnDestroy" event is first triggered after 15-20 seconds whereafter the application terminates. I am assuming this is because the sigaction handler is executed in a different thread than the UI is running and thus there is a synchronization issue.

For now, I have mitigated the issue by putting a disabled TTimer on the main form and the event handler for that timer is then calling "Close()" on the form. In the sigaction handler I then enable the TTimer on the form and now the termination of the application is "un-broken", both "OnClose" and "OnDestroy" are triggered as expected during system shutdown and when closing the application from the system monitor and there is no hanging.

Is this a bug in the Qt5 implementation, or is this behaviour normal? Is there a sleeker way around this than the TTimer approach?

Thanks! :)
« Last Edit: June 11, 2025, 08:00:30 pm by Fungus »

zeljko

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Application seems to hang during shutdown?
« Reply #1 on: June 11, 2025, 09:28:26 pm »
Please, attach simple project which shows your problem.

 

TinyPortal © 2005-2018