Summary: | ASTERISK-14115: [patch] astcanary: race when asterisk daemonizes | ||
Reporter: | Tzafrir Cohen (tzafrir) | Labels: | |
Date Opened: | 2009-05-13 04:33:44 | Date Closed: | 2009-05-18 14:30:42 |
Priority: | Minor | Regression? | No |
Status: | Closed/Complete | Components: | General |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ( 0) 20090513__issue15093__2.diff.txt ( 1) fork_sleep_test.c | |
Description: | I normally start asterisk daemonized (without -c and such). Sometimes (I still can't reproduce it) I immediately get the EX-CANARY message printed to the console. E.g.: Starting Asterisk PBX: The canary is no more. He has ceased to be! He's expired and gone to meet his maker! He's a stiff! Bereft of life, he rests in peace. His metabolic processes are now history! He's off the twig! He's kicked the bucket. He's shuffled off his mortal coil, run down the curtain, and joined the bleeding choir invisible!! THIS is an EX-CANARY. (Reducing priority) Note that this must have been printed before Asterisk has been detached from the console. The message itself is ast_log(LOG_WARNING). What we basically have is: canary_thread() { sleep(120) while(1) { if (no signs of life from canary) give the EX-CANARY message and quit; } } main: fork() { /* child */ exec(astcanary) } { /* parent */ ast_pthread_create_detached(canary_thread); } if (user asked to daemonize) daemon() } When running daemon(), we also fork. This does not interact well with sleep(2) as the attached test program demonstrates. | ||
Comments: | By: Tilghman Lesher (tilghman) 2009-05-13 11:54:35 Could you please be more explicit about what the test program shows? By: Tzafrir Cohen (tzafrir) 2009-05-13 12:25:43 Replaced with a slightly clearer one: tzafrir@sweetmorn:~$ gcc -Wall -o /tmp/fork_sleep_test -lpthread /tmp/fork_sleep_test.c tzafrir@sweetmorn:~$ /tmp/fork_sleep_test Starting, child keeps running... Main thread starting... Sleep thread sleeping... In child from fork Press Enter to continue In parent from fork /home/tzafrir (exited right away. I didn't have time to press Enter. This is how Asterisk behaves) tzafrir@sweetmorn:~$ /tmp/fork_sleep_test yes Starting, parent keeps running... Sleep thread sleeping... Main thread starting... In child from fork /home/tzafrir In parent from fork Press Enter to continue Sleep thread done sleeping. (I waited for 20 seconds, for the sleep to expire, and only the pressed Enter) By: Tilghman Lesher (tilghman) 2009-05-13 12:50:56 Well, if the ordering is the issue, then moving the code down after the daemon(3) should solve it, right? By: Tilghman Lesher (tilghman) 2009-05-18 12:08:13 Testing? Yes? No? Maybe so? By: Tzafrir Cohen (tzafrir) 2009-05-18 12:16:33 Tested in latest Debian packages. Seems to work so far. By: Digium Subversion (svnbot) 2009-05-18 14:17:16 Repository: asterisk Revision: 195320 U trunk/main/asterisk.c ------------------------------------------------------------------------ r195320 | tilghman | 2009-05-18 14:17:16 -0500 (Mon, 18 May 2009) | 9 lines Move the spawn of astcanary down, until after the call to daemon(3). This avoids possible conflicts with the internal implementation of daemon(3). (closes issue ASTERISK-14115) Reported by: tzafrir Patches: 20090513__issue15093__2.diff.txt uploaded by tilghman (license 14) Tested by: tzafrir ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=195320 By: Digium Subversion (svnbot) 2009-05-18 14:27:24 Repository: asterisk Revision: 195357 _U branches/1.6.0/ U branches/1.6.0/main/asterisk.c ------------------------------------------------------------------------ r195357 | tilghman | 2009-05-18 14:27:24 -0500 (Mon, 18 May 2009) | 16 lines Merged revisions 195320 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ........ r195320 | tilghman | 2009-05-18 14:17:15 -0500 (Mon, 18 May 2009) | 9 lines Move the spawn of astcanary down, until after the call to daemon(3). This avoids possible conflicts with the internal implementation of daemon(3). (closes issue ASTERISK-14115) Reported by: tzafrir Patches: 20090513__issue15093__2.diff.txt uploaded by tilghman (license 14) Tested by: tzafrir ........ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=195357 By: Digium Subversion (svnbot) 2009-05-18 14:30:31 Repository: asterisk Revision: 195358 _U branches/1.6.1/ U branches/1.6.1/main/asterisk.c ------------------------------------------------------------------------ r195358 | tilghman | 2009-05-18 14:30:30 -0500 (Mon, 18 May 2009) | 16 lines Merged revisions 195320 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ........ r195320 | tilghman | 2009-05-18 14:17:15 -0500 (Mon, 18 May 2009) | 9 lines Move the spawn of astcanary down, until after the call to daemon(3). This avoids possible conflicts with the internal implementation of daemon(3). (closes issue ASTERISK-14115) Reported by: tzafrir Patches: 20090513__issue15093__2.diff.txt uploaded by tilghman (license 14) Tested by: tzafrir ........ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=195358 By: Digium Subversion (svnbot) 2009-05-18 14:30:42 Repository: asterisk Revision: 195359 _U branches/1.6.2/ U branches/1.6.2/main/asterisk.c ------------------------------------------------------------------------ r195359 | tilghman | 2009-05-18 14:30:41 -0500 (Mon, 18 May 2009) | 16 lines Merged revisions 195320 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ........ r195320 | tilghman | 2009-05-18 14:17:15 -0500 (Mon, 18 May 2009) | 9 lines Move the spawn of astcanary down, until after the call to daemon(3). This avoids possible conflicts with the internal implementation of daemon(3). (closes issue ASTERISK-14115) Reported by: tzafrir Patches: 20090513__issue15093__2.diff.txt uploaded by tilghman (license 14) Tested by: tzafrir ........ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=195359 |