php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68409 exit hangs forever when running CLI script
Submitted: 2014-11-12 12:43 UTC Modified: 2014-11-13 17:42 UTC
From: grotagroten at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.6.2 OS: Windows/Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: grotagroten at hotmail dot com
New email:
PHP Version: OS:

 

 [2014-11-12 12:43 UTC] grotagroten at hotmail dot com
Description:
------------
I have a CLI script that hangs on termination. The script will call exit when it is done, the shutdown function will be called, destructors will be called, and then it just waits for nothing to happen. I have to manually terminate the process to get it to exit. It does not consume any resources, it just hangs forever. The same behaviour is observed with the die function. It appears on both 5.5 and 5.6.

Test script:
---------------
I do not have a simple test script that can reproduce it at the moment, but I have  a log from running the script with strace. 

I have uploaded the trace to the following location: http://www.filedropper.com/trace

The end of the trace looks like this, it seems to be polling for something.

fstat(12, {st_mode=S_IFREG|0777, st_size=1314, ...}) = 0
fstat(12, {st_mode=S_IFREG|0777, st_size=1314, ...}) = 0
fstat(12, {st_mode=S_IFREG|0777, st_size=1314, ...}) = 0
fstat(12, {st_mode=S_IFREG|0777, st_size=1314, ...}) = 0
mmap(NULL, 1314, PROT_READ, MAP_SHARED, 12, 0) = 0x7fc092237000
munmap(0x7fc092237000, 1314)            = 0
close(12)                               = 0
close(3)                                = 0
close(4)                                = 0
write(6, "\1\0\0\0\0\0\0\0", 8)         = 8
write(11, "\1\0\0\0\1", 5)              = 5
shutdown(11, SHUT_RDWR)                 = 0
close(11)                               = 0
munmap(0x7fc087db9000, 266240)          = 0
close(2)                                = 0
close(1)                                = 0
munmap(0x7fc092235000, 4096)            = 0
close(0)                                = 0
munmap(0x7fc092236000, 4096)            = 0
brk(0x2d38000)                          = 0x2d38000
munmap(0x7fc087d37000, 266240)          = 0
munmap(0x7fc087d78000, 266240)          = 0
munmap(0x7fc087e39000, 266240)          = 0
munmap(0x7fc087e7a000, 266240)          = 0
munmap(0x7fc087ebb000, 266240)          = 0
munmap(0x7fc087efc000, 266240)          = 0
munmap(0x7fc087f3d000, 266240)          = 0
munmap(0x7fc087f7e000, 266240)          = 0
munmap(0x7fc087fbf000, 266240)          = 0
munmap(0x7fc08c035000, 266240)          = 0
munmap(0x7fc08c076000, 266240)          = 0
munmap(0x7fc08c0b7000, 266240)          = 0
munmap(0x7fc092055000, 266240)          = 0
write(10, "\1\0\0\0\0\0\0\0", 8)        = 8
poll([{fd=5, events=POLLIN}], 1, 4294967295
Process 3037 detached
 <detached ...>

Expected result:
----------------
Script should terminate on exit

Actual result:
--------------
Script hangs forever

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-12 23:47 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2014-11-12 23:47 UTC] ab@php.net
I'm afraid there's not enough info. Please inspect the script and your setup. As you're saying all the request shutdown looks like gets done, that could be anything like some thread still polling on a connection which always stays open. I'd suggest the following checklist:

- deactivate all the non core extensions
- deactivate some parts of the script or replace some mocks
- if it's using some connections - try to kill the counterpart processes (if you can control them). If you see that EOF arrives - look for th ecorresponding code part.
- as last, check which core extensions you use, try deactivate one by one replacing the corresponding parts with mocks
- if it happens on the pure core only, probably no another way then script debugging, deactivating parts replacing them with mock and checking the result

That should be enough for the first time. Doing this you'll sure have some more perceptions to go further.

Thanks
 [2014-11-13 10:10 UTC] grotagroten at hotmail dot com
Thank you for pointing me in the right direction. The issue was related to the ZMQ extension and a lingering connection to a non-existing host. After setting a lingering value on the socket before disconnecting it, the script terminated as expected.
 [2014-11-13 17:42 UTC] ab@php.net
-Status: Feedback +Status: Not a bug
 [2014-11-13 17:42 UTC] ab@php.net
Thanks for the update. So kinda config issue :)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 07:00:01 2026 UTC