Lazarus

Programming => General => Topic started by: gsnak on August 13, 2020, 09:10:12 pm

Title: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: gsnak on August 13, 2020, 09:10:12 pm
I've recently installed Ubuntu 20.04 64bit and I've encountered problem that every GTK2 app started 25s. I reported it on launchpad (https://bugs.launchpad.net/ubuntu/+bug/1891245) and eventually was able to resolve it by installing appmenu-gtk2-module, restarting and then running /usr/libexec/gsd-xsettings

This works for other gtk2 apps, for example gmrun now starts instantly. However it did not fix lazarus-made apps. I started new lazarus project, added button, compiled it and run. The blank window appears immediately, but it's content became visible only after 25s delay. This only happen in lightweight WMs like openbox.

Here is strace ./Project1

...
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0) = 14
fcntl(14, F_GETFL)                      = 0x2 (flags O_RDWR)
fcntl(14, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
connect(14, {sa_family=AF_UNIX, sun_path="/run/user/1000/bus"}, 110) = 0
getpid()                                = 20113
geteuid()                               = 1000
getegid()                               = 1000
getpid()                                = 20113
geteuid()                               = 1000
getegid()                               = 1000
sendmsg(14, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="\0", iov_len=1}], msg_iovlen=1, msg_control=[{cmsg_len=28, cmsg_level=SOL_SOCKET, cmsg_type=SCM_CREDENTIALS, cmsg_data={pid=20113, uid=1000, gid=1000}}], msg_controllen=32, msg_flags=0}, MSG_NOSIGNAL) = 1
sendto(14, "AUTH\r\n", 6, MSG_NOSIGNAL, NULL, 0) = 6
recvfrom(14, "REJECTED EXTERNAL\r\n", 4096, 0, NULL, NULL) = 19
sendto(14, "AUTH EXTERNAL 31303030\r\n", 24, MSG_NOSIGNAL, NULL, 0) = 24
recvfrom(14, "OK d1e193bc144cb8f8d4f45a815f358"..., 4096, 0, NULL, NULL) = 37
sendto(14, "NEGOTIATE_UNIX_FD\r\n", 19, MSG_NOSIGNAL, NULL, 0) = 19
recvfrom(14, "AGREE_UNIX_FD\r\n", 4096, 0, NULL, NULL) = 15
sendto(14, "BEGIN\r\n", 7, MSG_NOSIGNAL, NULL, 0) = 7
write(17, "\1\0\0\0\0\0\0\0", 8)        = 8
eventfd2(0, EFD_CLOEXEC|EFD_NONBLOCK)   = 16
write(16, "\1\0\0\0\0\0\0\0", 8)        = 8
write(17, "\1\0\0\0\0\0\0\0", 8)        = 8
poll([{fd=16, events=POLLIN}], 1, 25000) = 1 ([{fd=16, revents=POLLIN}])
read(16, "\1\0\0\0\0\0\0\0", 16)        = 8
poll([{fd=16, events=POLLIN}], 1, 24998


... here is 25s delay


) = 0 (Timeout)
write(16, "\1\0\0\0\0\0\0\0", 8)        = 8
futex(0x14bc790, FUTEX_WAKE_PRIVATE, 2147483647) = 0
close(16)                               = 0
write(17, "\1\0\0\0\0\0\0\0", 8)        = 8
futex(0x7f602241df38, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x7f602241df38, FUTEX_WAKE_PRIVATE, 2147483647) = 0
statfs("/home/maly", {f_type=EXT2_SUPER_MAGIC, f_bsize=4096, f_blocks=59255762, f_bfree=57029660, f_bavail=54002204, f_files=15122432, f_ffree=14859840, f_fsid={val=[2534916902, 735370733]}, f_namelen=255, f_frsize=4096, f_flags=ST_VALID|ST_RELATIME}) = 0
futex(0x7f602241df38, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x7f602241df38, FUTEX_WAKE_PRIVATE, 2147483647) = 0
inotify_init1(IN_CLOEXEC)               = 16
fcntl(16, F_GETFL)                      = 0 (flags O_RDONLY)
fcntl(16, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
write(15, "\1\0\0\0\0\0\0\0", 8)        = 8
write(15, "\1\0\0\0\0\0\0\0", 8)        = 8
futex(0x14b0020, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x7f602241df38, FUTEX_WAKE_PRIVATE, 2147483647) = 0
inotify_add_watch(16, "/home/maly/.config/ibus/bus", IN_MODIFY|IN_ATTRIB|IN_CLOSE_WRITE|IN_MOVED_FROM|IN_MOVED_TO|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|IN_ONLYDIR) = 1
openat(AT_FDCWD, "/home/maly/.config/ibus/bus/0b994dfb915f499ba5a6a4702cf76e43-unix-0", O_RDONLY) = 18
fstat(18, {st_mode=S_IFREG|0664, st_size=379, ...}) = 0
read(18, "# This file is created by ibus-d"..., 4096) = 379
read(18, "", 4096)                      = 0
close(18)                               = 0
kill(13462, 0)                          = -1 ESRCH (No such process)
mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f601df64000
mprotect(0x7f601df65000, 8388608, PROT_READ|PROT_WRITE) = 0
clone(child_stack=0x7f601e763cf0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tid=[20119], tls=0x7f601e764700, child_tidptr=0x7f601e7649d0) = 20119
futex(0x1321ea0, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x7f602241dd80, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x7f602241df38, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x7f602247e2a0, FUTEX_WAIT_PRIVATE, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable)
futex(0x7f602247e2a0, FUTEX_WAKE_PRIVATE, 1) = 0
poll([{fd=4, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=4, revents=POLLIN|POLLOUT}])
...

When I'm debugging the project the delay starts at Application.run; then it takes 25s inside this in gtk2widgetset.inc:

    while g_main_context_pending(g_main_context_default) and (i>0) do
      begin
        if FGtkTerminated then
          break;
        if not g_main_context_iteration(g_main_context_default, False) then
          break;
        dec(i);
      end;

Any idea how to fix this?
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: ChrisR on August 14, 2020, 01:17:55 pm
See issue https://bugs.freepascal.org/view.php?id=36359 (https://bugs.freepascal.org/view.php?id=36359). This is not specific to Lazarus GTK2 applications, but impacts many GTK applications (KeepassXC, Filezilla, OnlyOffice Desktop-Editor, HexChat).

Despite the prevalence, this bug still exists, months after the initial report https://bugs.launchpad.net/ubuntu/+source/dbus/+bug/1852016 (https://bugs.launchpad.net/ubuntu/+source/dbus/+bug/1852016). Perhaps you can add your voice there to help get this prioritized.


The simplest solution is
  sudo apt-get install appmenu-gtk2-module
On the other hand, most Lazarus projects can now target QT5, which does not have this problem. It looks like GTK3 has issues that will not be fixed (e.g. unable to multi-sample OpenGL) now that development has moved to GTK4. Therefore, it seems like QT5 is the only modern and complete widgetset for Linux.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: gsnak on August 14, 2020, 02:35:44 pm
The only thing that worked was using "dbus-launch ./project1" so for every lazarus project I will create script that runs project executable via dbus-launch. I cannot use "dbus-launch openbox" because it is not "inherited" so if openbox runs other programs, it will no longer work. For example if i use "dbus-launch ./project1" it is fast, but if I run "dbus-launch xterm" and in xterm I run ./project it is slow again. It is annoying but at least it works.

If someone know of proper fix let me know.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: Warfley on August 14, 2020, 02:43:24 pm
Despite the prevalence, this bug still exists, months after the initial report https://bugs.launchpad.net/ubuntu/+source/dbus/+bug/1852016 (https://bugs.launchpad.net/ubuntu/+source/dbus/+bug/1852016). Perhaps you can add your voice there to help get this prioritized.

I wouldn't bet on it being fixed at all, as GTK2 is pretty much a dead horse now. GTK4 is close to being released and most Linux distros that have relied on GTK2 (like XFCE) are currently updating to GTK3. GTK2 is now just maintained by a small (and shrinking) number of people, so there is not much workforce behind to fix bugs anymore, especeially if the bugs aren't that bad and can be circumvented
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: Handoko on August 14, 2020, 02:46:10 pm
That is bad. GTK3 implementation is LCL Interface is still in alpha state now.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: mdalacu on August 14, 2020, 03:21:15 pm
I think the problem disappears if you install a certain package...i don't know what.
My applications are opening fast without any prefixes. I have tested this in Ubuntu 19.09 2004 with Gnome, Xface and kde DE.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: Handoko on August 14, 2020, 03:28:04 pm
My Ubuntu Mate 20.04 64-bit is working good, never have any performance issue.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: gsnak on August 14, 2020, 03:29:16 pm
Installing package appmenu-gtk2-module only works in gnome, maybe xfce. In small VMs (openbox, ...) it doesn't work.

Maybe we could try to find what file is GTK trying to open for 25000ms and add option to GTK that would skip this file (it doesn't find it anyway and app still works.)
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: af0815 on August 14, 2020, 04:49:29 pm
Installing package appmenu-gtk2-module only works in gnome, maybe xfce. In small VMs (openbox, ...) it doesn't work.
there is a quote for SmlallVMs in the Bugreport
Quote
I had to start openbox with:
/usr/bin/dbus-launch --exit-with-session openbox --startup $HOME/.config/openbox/autostart
The dbus-launch --exit-with-session apparently starts some service that gnome apps now insist on.
maybe it works for your openbox, if the appmenue... does not work for you.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: gsnak on August 14, 2020, 05:36:25 pm
I've tried it, it doesn't work.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: Raul_ES on August 14, 2020, 06:29:29 pm
My Ubuntu Mate 20.04 64-bit is working good, never have any performance issue.

I've been experiencing general performance issues (starting applications and closing them mainly) in two of my three Ubuntu 20.04 installations (a desktop and a netbook) for a few days since certain packages where updated. Recentlly, everything is back again to normall performance. Not really sure what happened...
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: AmatCoder on August 14, 2020, 09:46:54 pm
25 seconds is the "service_start_timeout" default limit from dbus-daemon.

Here the problem is that GTK_MODULES environment variable is not set when dbus-daemon is launched at start of session (it is normally launched by an init script).

You need to update it with:
Code: [Select]
dbus-update-activation-environment --systemd GTK_MODULES
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: ChrisR on August 14, 2020, 11:33:24 pm
For me
    sudo apt-get install appmenu-gtk2-module
worked, but it did require not only an install, but also re-booting the computer.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: gsnak on August 15, 2020, 08:21:50 am
25 seconds is the "service_start_timeout" default limit from dbus-daemon.

Here the problem is that GTK_MODULES environment variable is not set when dbus-daemon is launched at start of session (it is normally launched by an init script).

You need to update it with:
Code: [Select]
dbus-update-activation-environment --systemd GTK_MODULES

It doesn't work:

$ dbus-update-activation-environment --systemd GTK_MODULES
dbus-update-activation-environment: warning: error sending to systemd: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: gsnak on August 15, 2020, 08:55:04 am
Gentlemen, I found it. I compared `env` between unity and openbox and found it. It is as simple as putting this:

    export GTK_MODULES=gail:atk-bridge:appmenu-gtk-module

In ~/.profile. Now everything is fast.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: gour on August 15, 2020, 09:50:29 am
GTK4 is close to being released and most Linux distros that have relied on GTK2 (like XFCE) are currently updating to GTK3.

What is the situation about Lazarus in regard to GTK4?
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: Handoko on August 15, 2020, 06:53:43 pm
As far as I know GTK4 haven't started yet:
https://wiki.lazarus.freepascal.org/Roadmap#General_status_of_LCL_interfaces
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: Blade on August 15, 2020, 09:54:34 pm
Gentlemen, I found it. I compared `env` between unity and openbox and found it. It is as simple as putting this:

    export GTK_MODULES=gail:atk-bridge:appmenu-gtk-module

In ~/.profile. Now everything is fast.

Maybe you should indicated in the title <SOLVED>, so other people will know there is a solution.
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: AmatCoder on August 16, 2020, 12:28:13 am
Installing appmenu-gtk-module package should not be necessary.

It is just a workaround. It works because it contains this systemd service:
https://github.com/rilian-la-te/vala-panel-appmenu/blob/master/subprojects/appmenu-gtk-module/data/appmenu-gtk-module.service.in (https://github.com/rilian-la-te/vala-panel-appmenu/blob/master/subprojects/appmenu-gtk-module/data/appmenu-gtk-module.service.in)

As you can see it updates GTK_MODULES environment variable after dbus-daemon execution (that's why you need to reboot) and only for xfce, mate and gnome (that's why it don't work with openbox).
Title: Re: All GTK2 lazarus-made apps take 25s to start in ubuntu 20.04 64bit in openbox
Post by: dbannon on August 16, 2020, 02:28:18 am
Some conflicting statements here.

> Gentlemen, I found it. I compared `env` between unity ..

Unity ?? Seriously ? anyway ....

We do know that on most desktops, appmenu-gtk-module 'fixes' the problem.  In an earlier Ubuntu, they left it off the list of dependencies for GTK2.  Manually installing it fixed the problem but introduced other issues.  Since then, Canonical ship gtk2 AND appmenu... as standard, out of the box and it all works. 

Can we please clarify, does installing appmenu-gtk-module fix the OpenBox situation ?

If  an OpenBox distro has a problem and its fixed by manually installing appmenu-gtk-module, then the problem is, again, that the packagers have not included appmenu-gtk-modual as part of GTK2 and they should have.

We cannot say to our OpenBox end users that they need to do some system reconfig before they can use our app, thats too hard. We can just get away with saying "manually install appmenu-gtk-module". Note we cannot just add appmenu-gtk-module to our app's list of dependencies because older distributions do not have (or need) appmenu-gtk-module and demanding it will break the install.

This is one of those problems that just keeps on giving ....

Davo

TinyPortal © 2005-2018