[asterisk-bugs] [JIRA] Updated: (ASTERISK-20532) AGI script fork()s, Asterisk doesn't keep processing the dialplan when parent dies

Omri Bahumi (JIRA) noreply at issues.asterisk.org
Mon Oct 8 15:00:27 CDT 2012


     [ https://issues.asterisk.org/jira/browse/ASTERISK-20532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Omri Bahumi updated ASTERISK-20532:
-----------------------------------

    Description: 
When an AGI script forks, Asterisk won't keep processing the dialplan when the parent dies.
By looking at the AGI code I've noticed it waits for an EOF on the stdout file descriptor, and not for the process to die.

Attached two Python AGI scripts (uses pyst-0.4.38).

Problematic example: you'll notice the dialplan stops processing until both the parent and child exit (hence closing stdout fd).
Workaround example: the execution continues when the parent exits and the child closes stdout, not waiting for the entire script execution to terminate.

  was:
When an AGI script forks, Asterisk won't keep processing the dialplan when the parent dies.
By looking at the AGI code I've noticed it waits for an EOF on the stdout file descriptor, and not for the process to die.

Problematic code (this code uses pyst-0.4.38):
#!/usr/bin/python
import sys, os, time
import asterisk.agi, asterisk.manager

def main():
	agi = asterisk.agi.AGI()
	agi.hangup()
	
	if os.fork():
		# parent process
		sys.exit(0)
	else:
		# child process
		os.setsid()
		time.sleep(10)

if __name__ == '__main__':
	main()


Workaround code (addition: close sys.stdout on child process):
#!/usr/bin/python
import sys, os, time
import asterisk.agi, asterisk.manager

def main():
	agi = asterisk.agi.AGI()
	agi.hangup()
	
	if os.fork():
		# parent process
		sys.exit(0)
	else:
		# child process
		os.setsid()
		os.close(sys.stdout.fileno())
		time.sleep(10)

if __name__ == '__main__':
	main()

Problematic example: you'll notice the dialplan stops processing until both the parent and child exit (hence closing stdout fd).
Workaround example: the execution continues when the parent exits and the child closes stdout, not waiting for the entire script execution to terminate.


> AGI script fork()s, Asterisk doesn't keep processing the dialplan when parent dies
> ----------------------------------------------------------------------------------
>
>                 Key: ASTERISK-20532
>                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-20532
>             Project: Asterisk
>          Issue Type: Bug
>      Security Level: None
>          Components: Resources/res_agi
>         Environment: Debian 6 64bits
>            Reporter: Omri Bahumi
>            Severity: Minor
>
> When an AGI script forks, Asterisk won't keep processing the dialplan when the parent dies.
> By looking at the AGI code I've noticed it waits for an EOF on the stdout file descriptor, and not for the process to die.
> Attached two Python AGI scripts (uses pyst-0.4.38).
> Problematic example: you'll notice the dialplan stops processing until both the parent and child exit (hence closing stdout fd).
> Workaround example: the execution continues when the parent exits and the child closes stdout, not waiting for the entire script execution to terminate.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira



More information about the asterisk-bugs mailing list