Bug 276461 - [patch] automoc sometimes freezes under FreeBSD
Summary: [patch] automoc sometimes freezes under FreeBSD
Status: RESOLVED UNMAINTAINED
Alias: None
Product: buildsystem
Classification: Developer tools
Component: KDE4 (cmake) (show other bugs)
Version: unspecified
Platform: Compiled Sources FreeBSD
: NOR normal
Target Milestone: ---
Assignee: Alexander Neundorf
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-25 12:16 UTC by David Naylor
Modified: 2018-11-19 17:37 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Correctly check cmake QProcess start / Fixes automoc4 freeze under FreeBSD (1.33 KB, patch)
2011-06-25 12:16 UTC, David Naylor
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Naylor 2011-06-25 12:16:08 UTC
Created attachment 61311 [details]
Correctly check cmake QProcess start / Fixes automoc4 freeze under FreeBSD

Version:           4.6 (using KDE 4.6.4) 
OS:                FreeBSD

Automoc sometimes freezes under FreeBSD.  It appears to happen with the QProcess under echoColor.  

The attached patch fixes the problem.

Reproducible: Always

Steps to Reproduce:
# cd /usr/ports/games/kdegames4
# make

Actual Results:  
Port stalls while building

Expected Results:  
Port completes build

dragon# gdb `which automoc4`
GNU gdb 6.1.1 [FreeBSD]
(gdb) attach 24682
(gdb) info thr
  2 Thread 802c07400 (LWP 101969/initial thread)  0x000000080165080c in select ()
   from /lib/libc.so.7
* 1 Thread 802c08800 (LWP 102119/automoc4)  0x000000080165080c in select ()
   from /lib/libc.so.7
(gdb) bt
#0  0x000000080165080c in select () from /lib/libc.so.7
#1  0x0000000800a54f3d in QProcessManager::run (this=0x800e1e600)
    at io/qprocess_unix.cpp:245
#2  0x000000080094e84e in QThreadPrivate::start (arg=0x800e1e600)
    at thread/qthread_unix.cpp:320
#3  0x000000080229a224 in pthread_getprio () from /lib/libthr.so.3
#4  0x0000000000000000 in ?? ()
Error accessing memory address 0x7fffffbfe000: Bad address.
(gdb) thr 2
[Switching to thread 2 (Thread 802c07400 (LWP 101969/initial thread))]#0  0x000000080165080c in select () from /lib/libc.so.7
(gdb) bt
#0  0x000000080165080c in select () from /lib/libc.so.7
#1  0x0000000800ab66fc in qt_safe_select (nfds=15, fdread=0x7fffffffc780, fdwrite=0x0,
    fdexcept=0x0, orig_timeout=0x0) at kernel/qcore_unix.cpp:82
#2  0x0000000800a52848 in select_msecs (nfds=15, fdread=0x7fffffffc780, fdwrite=0x0,
    timeout=-1) at io/qprocess_unix.cpp:880
#3  0x0000000800a538b4 in QProcessPrivate::waitForStarted (this=0x802cff300, msecs=-1)
    at io/qprocess_unix.cpp:913
#4  0x0000000800a07377 in QProcess::waitForStarted (this=0x7fffffffc900, msecs=-1)
    at io/qprocess.cpp:1665
#5  0x0000000800a07418 in QProcess::waitForFinished (this=0x7fffffffc900, msecs=-1)
    at io/qprocess.cpp:1735
#6  0x000000000040a800 in AutoMoc::echoColor (this=0x7fffffffd4c0, msg=@0x7fffffffca70)
    at /tmp/usr/ports/devel/automoc4/work/automoc4-0.9.88/kde4automoc.cpp:74
#7  0x0000000000404c9c in AutoMoc::generateMoc (this=0x7fffffffd4c0,
    sourceFile=@0x802c1cd10, mocFileName=@0x802c1cd18)
    at /tmp/usr/ports/devel/automoc4/work/automoc4-0.9.88/kde4automoc.cpp:569
#8  0x0000000000407b31 in AutoMoc::run (this=0x7fffffffd4c0)
    at /tmp/usr/ports/devel/automoc4/work/automoc4-0.9.88/kde4automoc.cpp:470
#9  0x0000000000408c55 in main (argc=6, argv=0x7fffffffd598)
    at /tmp/usr/ports/devel/automoc4/work/automoc4-0.9.88/kde4automoc.cpp:114
(gdb) The program is running.  Quit anyway (and detach it)? (y or n) y
Detaching from program: /usr/local/bin/automoc4, process 24682
dragon# gdb `which automoc4`
GNU gdb 6.1.1 [FreeBSD]
(gdb) attach 24683
(gdb) info thr
Cannot get thread info: invalid key
(gdb) bt
#0  0x00000008022a195c in pthread_kill () from /lib/libthr.so.3
#1  0x000000080229bcac in pthread_getschedparam () from /lib/libthr.so.3
#2  0x000000080229ff5a in pthread_mutex_getprioceiling () from /lib/libthr.so.3
#3  0x00000008022a0435 in pthread_mutex_lock () from /lib/libthr.so.3
#4  0x000000080164ff9e in flockfile () from /lib/libc.so.7
#5  0x0000000801625ee5 in fileno () from /lib/libc.so.7
#6  0x0000000800a53d79 in QProcessPrivate::execChild (this=0x802cff300,
    workingDir=0x0, path=0x0, argv=0x802c17840, envp=0x0) at io/qprocess_unix.cpp:712
#7  0x0000000800a56c33 in QProcessPrivate::startProcess (this=0x802cff300)
    at io/qprocess_unix.cpp:665
#8  0x0000000800a06eb8 in QProcess::start (this=0x7fffffffc900,
    program=@0x7fffffffd4e8, arguments=@0x7fffffffc8f0, mode=@0x7fffffffc910)
    at io/qprocess.cpp:1960
#9  0x000000000040a7f2 in AutoMoc::echoColor (this=0x7fffffffd4c0, msg=@0x7fffffffca70)
    at /tmp/usr/ports/devel/automoc4/work/automoc4-0.9.88/kde4automoc.cpp:73
#10 0x0000000000404c9c in AutoMoc::generateMoc (this=0x7fffffffd4c0,
    sourceFile=@0x802c1cd10, mocFileName=@0x802c1cd18)
    at /tmp/usr/ports/devel/automoc4/work/automoc4-0.9.88/kde4automoc.cpp:569
#11 0x0000000000407b31 in AutoMoc::run (this=0x7fffffffd4c0)
    at /tmp/usr/ports/devel/automoc4/work/automoc4-0.9.88/kde4automoc.cpp:470
#12 0x0000000000408c55 in main (argc=6, argv=0x7fffffffd598)
    at /tmp/usr/ports/devel/automoc4/work/automoc4-0.9.88/kde4automoc.cpp:114
(gdb) The program is running.  Quit anyway (and detach it)? (y or n) y
Detaching from program: /usr/local/bin/automoc4, process 24683
Comment 1 Oswald Buddenhagen 2011-06-25 14:23:56 UTC
this patch is bogus. waitForFinished() implies waitForStarted(), so the only thing you change is the timeout on waitForStarted().
Comment 2 David Naylor 2011-06-25 15:11:19 UTC
Although waitForFinished() implies waitForStarted(), waitForFinished() also creates a QElapsedTimer before calling waitForStarted().  At a guess QElapsedTimer creates a separate thread.  

FreeBSD is rather sensitive when it comes to mixing threads and forks.  

This test has been tested by multiple people at kde-freebsd@ and does have a definite change in the behavior of automoc.
Comment 3 Oswald Buddenhagen 2011-06-26 06:54:02 UTC
how about properly investigating rather than guessing?
and if this is indeed a problem in qt, how about fixing it instead of working around in kde?
Comment 4 David Naylor 2011-06-26 21:02:01 UTC
I looked at the implementation of QElapsedTimer and it does not use any threads, however QProcess for unix does.  

Looking at the traceback from the second automoc4 instance:
#0  0x00000008022a195c in pthread_kill () from /lib/libthr.so.3
#1  0x000000080229bcac in pthread_getschedparam () from /lib/libthr.so.3
#2  0x000000080229ff5a in pthread_mutex_getprioceiling () from /lib/libthr.so.3
#3  0x00000008022a0435 in pthread_mutex_lock () from /lib/libthr.so.3
#4  0x000000080164ff9e in flockfile () from /lib/libc.so.7
#5  0x0000000801625ee5 in fileno () from /lib/libc.so.7

it looks like automoc4 encounters a deadlock while trying to get the fileno() of stdout (execChld in qprocess_unix.cpp).  As far as I know (another guess) all FILE locks should be released in the child instance of a fork, and my brief attempts to verify that confirms.  I do not know how a FILE could be locks at that stage in a child of a fork.  

While reading through qprocess_unix.cpp I saw the signal handler uses a fprintf() function.  That function does not appear in the list of functions that can be safely called from "signal-catching functions" from sigaction(2) man pages.  fprintf does eventually call flockfile() in its implementation in FreeBSD, leading me to wonder if this could be the cause of the problem?
Comment 5 Alexander Neundorf 2011-06-27 20:48:36 UTC
Does this also happen with the automoc version which doesn't use Qt ?
If not, maybe we should merge that branch into master.
https://projects.kde.org/projects/kdesupport/automoc/repository/show?rev=no-qt

Alex
Comment 6 David Naylor 2011-07-24 10:54:07 UTC
I had a look at QProcess and it is not POSIX compliant.  The SIGCHLD handler calls functions that are not allowed from a signal handler (according to sigaction(2), section NOTES).  FreeBSD has a tendency to trigger such bugs however I am no longer able to reproduce this.  

I will try and give the no-qt branch a test run and report back my results.  

I am willing create a patch to "fix" this issue, if someone is willing to upstream the patch?
Comment 7 Oswald Buddenhagen 2011-07-24 15:18:31 UTC
a fix for qprocess (or at least a precise bug report) would be most welcom
Comment 8 David Naylor 2011-07-28 19:21:30 UTC
Having a closer look at the signal handler I see it uses qt_safe_write, which calls QT_WRITE, which is originally defined as ::write.  Looking at sigaction(2) write(2) is on the list of acceptable functions.  

It appears this is a FreeBSD specific error and that I incorrectly diagnosed the problem (again).  Apologies.  

It is not apparent to me why Qt uses a pipe and not wait(2) (or some wait variant).  

P.S. I'm currently running a build with automoc4-noqt and will report back shortly...
Comment 9 David Naylor 2011-09-18 12:18:24 UTC
I can confirm that automoc4-noqt does not introduce any regressions when used as a replacement for automoc4.
Comment 10 Max 2011-11-14 15:29:38 UTC
Alexander, can you make a release for automoc4-noqt? We could test it with all packages on FreeBSD build cluster.
Comment 11 Raphael Kubo da Costa 2011-11-14 20:53:56 UTC
(In reply to comment #10)
> Alexander, can you make a release for automoc4-noqt? We could test it with all
> packages on FreeBSD build cluster.

Actually, automoc4-noqt got integrated into CMake itself starting with CMake 2.8.6: http://blogs.kde.org/node/4495
Comment 12 Steve Wills 2011-12-29 02:53:54 UTC
This bug can probably be closed. We have worked around it by enabling -pthread:

http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/automoc4/files/patch-CMakeLists.txt?rev=1.1;content-type=text%2Fplain
Comment 13 Oswald Buddenhagen 2012-01-02 13:52:23 UTC
this isn't exactly a workaround ... *of course* qt4 apps need to be compiled with pthread support, so this is a plain bug in the makefile. alex, can you please deal with the patch (dunno if it's kde-ish enough).
Comment 14 Raphael Kubo da Costa 2012-01-02 14:05:08 UTC
(In reply to comment #13)
> this isn't exactly a workaround ... *of course* qt4 apps need to be compiled
> with pthread support, so this is a plain bug in the makefile.

ldd shows automoc already linked to pthread before on FreeBSD, but it looks like it needs to come as a dependency before libc itself so some threading code is properly initialized (see 
http://www.freebsd.org/cgi/query-pr.cgi?pr=163512).

It looks like this sort of problem does not exist on Linux (does it link to pthread automatically?), so it looks more of a braindead issue on FreeBSD.
Comment 15 Oswald Buddenhagen 2012-01-02 14:12:05 UTC
well, different does not necessarily mean braindead. ;)
in either case the kde buildsystem should abstract this away if reasonably possible.
Comment 16 Andrew Crouthamel 2018-11-10 03:16:41 UTC
Dear Bug Submitter,

This bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version? I am setting the status to NEEDSINFO pending your response, please change the Status back to REPORTED when you respond.

Thank you for helping us make KDE software even better for everyone!
Comment 17 David Naylor 2018-11-19 17:37:58 UTC
automoc4 is no longer maintained.