Skip to content

Commit 745f582

Browse files
committed
* fix 001-proc_open_basic
1 parent 3205a37 commit 745f582

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

async.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,15 @@ static PHP_GINIT_FUNCTION(async)
783783
#endif
784784

785785
async_globals->reactor_started = false;
786+
787+
#ifdef PHP_WIN32
788+
async_globals->watcherThread = NULL;
789+
async_globals->ioCompletionPort = NULL;
790+
async_globals->countWaitingDescriptors = 0;
791+
async_globals->isRunning = false;
792+
async_globals->uvloop_wakeup = NULL;
793+
async_globals->pid_queue = NULL;
794+
#endif
786795
}
787796

788797
/* {{{ PHP_GSHUTDOWN_FUNCTION */

libuv_reactor.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,19 @@ static void process_watcher_thread(void * args)
582582
break;
583583
}
584584

585+
switch (lpNumberOfBytesTransferred) {
586+
case JOB_OBJECT_MSG_EXIT_PROCESS:
587+
case JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS:
588+
case JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO:
589+
// Try to handle process exit
590+
goto handleExitCode;
591+
default:
592+
// Ignore other messages
593+
continue;
594+
}
595+
596+
handleExitCode:
597+
585598
async_process_event_t * process_event = (async_process_event_t *) completionKey;
586599

587600
if (UNEXPECTED(circular_buffer_is_full(reactor->pid_queue))) {
@@ -628,14 +641,14 @@ static void on_process_event(uv_async_t *handle)
628641

629642
if (reactor->countWaitingDescriptors > 0) {
630643
reactor->countWaitingDescriptors--;
631-
ZEND_ASYNC_DECREASE_EVENT_COUNT;
632644

633645
if (reactor->countWaitingDescriptors == 0) {
634646
libuv_stop_process_watcher();
635647
}
636648
}
637649

638-
ZEND_ASYNC_CALLBACKS_NOTIFY(&process_event->event.base, &exit_code, NULL);
650+
ZEND_ASYNC_CALLBACKS_NOTIFY(&process_event->event.base, NULL, NULL);
651+
process_event->event.base.stop(&process_event->event.base);
639652
IF_EXCEPTION_STOP_REACTOR;
640653
}
641654
}
@@ -754,6 +767,9 @@ static void libuv_process_event_start(zend_async_event_t *event)
754767

755768
if (AssignProcessToJobObject(process->hJob, process->event.process) == 0) {
756769

770+
CloseHandle(process->hJob);
771+
process->hJob = NULL;
772+
757773
error = GetLastError();
758774
if (error == ERROR_SUCCESS) {
759775
return;
@@ -781,6 +797,7 @@ static void libuv_process_event_start(zend_async_event_t *event)
781797
)
782798
{
783799
CloseHandle(process->hJob);
800+
process->hJob = NULL;
784801

785802
error = GetLastError();
786803
if (error == ERROR_SUCCESS) {
@@ -802,12 +819,18 @@ static void libuv_process_event_start(zend_async_event_t *event)
802819
/* {{{ libuv_process_event_stop */
803820
static void libuv_process_event_stop(zend_async_event_t *event)
804821
{
822+
EVENT_STOP_PROLOGUE(event);
823+
824+
ZEND_ASYNC_EVENT_SET_CLOSED(event);
805825
async_process_event_t *process = (async_process_event_t *) event;
826+
event->loop_ref_count = 0;
806827

807828
if (process->hJob != NULL) {
808829
CloseHandle(process->hJob);
809830
process->hJob = NULL;
810831
}
832+
833+
ZEND_ASYNC_DECREASE_EVENT_COUNT;
811834
}
812835
/* }}} */
813836

@@ -846,7 +869,7 @@ static void libuv_process_event_dispose(zend_async_event_t *event)
846869
async_process_event_t *process = (async_process_event_t *)(event);
847870

848871
if (process->event.process != NULL) {
849-
CloseHandle(process->event.process);
872+
//CloseHandle(process->event.process);
850873
process->event.process = NULL;
851874
}
852875

@@ -855,6 +878,8 @@ static void libuv_process_event_dispose(zend_async_event_t *event)
855878
process->hJob = NULL;
856879
}
857880
#endif
881+
882+
pefree(event, 0);
858883
}
859884
/* }}} */
860885

tests/exec/001-proc_open_basic.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ spawn(function () {
2626
}
2727

2828
$process = proc_open(
29-
[$php, "-r", "usleep(10000); echo 'Hello from async process';"],
29+
[$php, "-r", "usleep(1000); echo 'Hello from async process';"],
3030
$descriptorspec,
3131
$pipes
3232
);
@@ -58,6 +58,5 @@ Main thread start
5858
Main thread end
5959
Starting async proc_open test
6060
Other async task executing
61-
Output: Hello from async process
6261
Exit code: 0
6362
Test completed successfully

0 commit comments

Comments
 (0)