{"action":"created","issue":{"url":"https://api.github.com/repos/krakjoe/pthreads/issues/273","labels_url":"https://api.github.com/repos/krakjoe/pthreads/issues/273/labels{/name}","comments_url":"https://api.github.com/repos/krakjoe/pthreads/issues/273/comments","events_url":"https://api.github.com/repos/krakjoe/pthreads/issues/273/events","html_url":"https://github.com/krakjoe/pthreads/issues/273","id":30212484,"number":273,"title":"tests/killed-info times out","user":{"login":"2072","id":22638,"avatar_url":"https://avatars.githubusercontent.com/u/22638?v=3","gravatar_id":"","url":"https://api.github.com/users/2072","html_url":"https://github.com/2072","followers_url":"https://api.github.com/users/2072/followers","following_url":"https://api.github.com/users/2072/following{/other_user}","gists_url":"https://api.github.com/users/2072/gists{/gist_id}","starred_url":"https://api.github.com/users/2072/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2072/subscriptions","organizations_url":"https://api.github.com/users/2072/orgs","repos_url":"https://api.github.com/users/2072/repos","events_url":"https://api.github.com/users/2072/events{/privacy}","received_events_url":"https://api.github.com/users/2072/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2014-03-26T13:50:43Z","updated_at":"2015-01-04T04:38:46Z","closed_at":null,"body":"```\r\nPHP         : /opt/php-5.5.9/bin/php\r\nPHP_SAPI    : cli\r\nPHP_VERSION : 5.5.9\r\nZEND_VERSION: 2.5.0\r\nPHP_OS      : Linux - Linux vps44763 2.6.32-042stab084.14 #1 SMP Mon Dec 16 18:16:56 MSK 2013 x86_64\r\nINI actual  : /home/john/src/pthreads/tmp-php.ini\r\nMore .INIs  :\r\nCWD         : /home/john/src/pthreads\r\nExtra dirs  :\r\nVALGRIND    : Not used\r\n```\r\n\r\n```\r\n---- EXPECTED OUTPUT\r\nbool(true)\r\narray(4) {\r\n  [\"scope\"]=>\r\n  string(10) \"TestThread\"\r\n  [\"function\"]=>\r\n  string(3) \"run\"\r\n  [\"file\"]=>\r\n  string(%d) \"%s\"\r\n  [\"line\"]=>\r\n  int(%d)\r\n}\r\n---- ACTUAL OUTPUT\r\n** ERROR: process timed out **\r\n---- FAILED\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/krakjoe/pthreads/issues/comments/68620832","html_url":"https://github.com/krakjoe/pthreads/issues/273#issuecomment-68620832","issue_url":"https://api.github.com/repos/krakjoe/pthreads/issues/273","id":68620832,"user":{"login":"2072","id":22638,"avatar_url":"https://avatars.githubusercontent.com/u/22638?v=3","gravatar_id":"","url":"https://api.github.com/users/2072","html_url":"https://github.com/2072","followers_url":"https://api.github.com/users/2072/followers","following_url":"https://api.github.com/users/2072/following{/other_user}","gists_url":"https://api.github.com/users/2072/gists{/gist_id}","starred_url":"https://api.github.com/users/2072/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2072/subscriptions","organizations_url":"https://api.github.com/users/2072/orgs","repos_url":"https://api.github.com/users/2072/repos","events_url":"https://api.github.com/users/2072/events{/privacy}","received_events_url":"https://api.github.com/users/2072/received_events","type":"User","site_admin":false},"created_at":"2015-01-04T04:38:46Z","updated_at":"2015-01-04T04:38:46Z","body":"Since I'm able to reproduce the issue easily I decided to find out what's going on:\r\n\r\nI made the following changes to make Pthreads display some debug info: https://github.com/2072/pthreads/commit/4df66eab3a54bb3dd7ad311341219496480f61d7\r\n\r\nThen I executed the following test script:\r\n```php\r\n<?php\r\nerror_reporting(E_ALL | E_STRICT);\r\nini_set(\"display_startup_errors\", true);\r\n\r\nclass TestThread extends Thread\r\n{\r\n    public function run()\r\n    {\r\n        sleep(5);\r\n    }\r\n}\r\n\r\n$t = new TestThread();\r\n$t->start();\r\n$t->kill();\r\n$t->join();\r\n\r\nvar_dump($t->isTerminated());\r\nvar_dump($t->getTerminationInfo());\r\n```\r\n\r\nand obtained the following output:\r\n\r\n```\r\n1F3CBF0 is in pthreads_state_set() PHP line: 0\r\nJoining from 1BFEB20... from php line 16\r\n1F3CBF0 is in pthreads_state_set() PHP line: 0\r\n\r\n HEY!! I (1F3CBF0) am already in there!: 6\r\n\r\nI (1F3CBF0) was murdered while changing state: 6! (on kill pthreads_state_set() returned: 1)\r\nwe were killed while in 'pthread_cond_broadcast()' a dead lock is on the move. Sleeping for 120s\r\n```\r\n\r\nWhile it slept I attach gdb and got the following backtrace on thread #2 (1F3CBF0):\r\n\r\n```\r\n#0  0x00007f18b312e2bd in nanosleep () at ../sysdeps/unix/syscall-template.S:82\r\n#1  0x00007f18b312e130 in __sleep (seconds=<optimized out>, seconds@entry=120) at ../sysdeps/unix/sysv/linux/sleep.c:138\r\n#2  0x00007f18b18942e0 in pthreads_kill_handler (signo=10) at /home/john/src/pthreads/src/object.c:838\r\n#3  <signal handler called>\r\n#4  pthread_cond_broadcast@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S:98\r\n#5  0x00007f18b188f4f7 in pthreads_synchro_notify (sync=<optimized out>, tsrm_ls=tsrm_ls@entry=0x1687bf0) at /home/john/src/pthreads/src/synchro.c:96\r\n#6  0x00007f18b188f9e5 in pthreads_state_set (state=0x1686cf0, mask=mask@entry=2, tsrm_ls=0x1687bf0, tsrm_ls@entry=0x84) at /home/john/src/pthreads/src/state.c:108\r\n#7  0x00007f18b1894dda in pthreads_routine (arg=0x1686360) at /home/john/src/pthreads/src/object.c:980\r\n#8  0x00007f18b3414b50 in start_thread (arg=<optimized out>) at pthread_create.c:304\r\n#9  0x00007f18b315e7bd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112\r\n#10 0x0000000000000000 in ?? ()\r\n```\r\n\r\nSo the problem is obvious now, we can fix this either by fixing the test so that it waits for the thread to be started before killing it or the kill handler must be made more clever but since killing threads is not a recommended practice anyway, fixing the test is probably enough..."}}