Skip to content

Commit a5b3a18

Browse files
brstgtkelunik
authored andcommitted
Don't exit from finally in generator. Send exit code in shutdown function instead.
1 parent 3770b85 commit a5b3a18

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

lib/Process.php

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ public function stop(): \Generator {
7676
} catch (\Throwable $uncaught) {
7777
$this->exitCode = 1;
7878
$this->logger->critical($uncaught);
79-
} finally {
80-
static::exit();
8179
}
8280
}
8381

@@ -101,37 +99,41 @@ private function registerSignalHandler() {
10199

102100
private function registerShutdownHandler() {
103101
register_shutdown_function(function () {
104-
if (!$err = \error_get_last()) {
105-
return;
106-
}
107-
108-
switch ($err["type"]) {
109-
case E_ERROR:
110-
case E_PARSE:
111-
case E_USER_ERROR:
112-
case E_CORE_ERROR:
113-
case E_CORE_WARNING:
114-
case E_COMPILE_ERROR:
115-
case E_COMPILE_WARNING:
116-
case E_RECOVERABLE_ERROR:
117-
break;
118-
default:
119-
return;
120-
}
121-
122-
$this->exitCode = 1;
123-
$msg = "{$err["message"]} in {$err["file"]} on line {$err["line"]}";
124-
125-
$previous = Loop::get();
126-
127102
try {
128-
Loop::set((new Loop\DriverFactory)->create());
129-
Loop::run(function () use ($msg) {
130-
$this->logger->critical($msg);
131-
yield from $this->stop();
132-
});
103+
if (!$err = \error_get_last()) {
104+
return;
105+
}
106+
107+
switch ($err["type"]) {
108+
case E_ERROR:
109+
case E_PARSE:
110+
case E_USER_ERROR:
111+
case E_CORE_ERROR:
112+
case E_CORE_WARNING:
113+
case E_COMPILE_ERROR:
114+
case E_COMPILE_WARNING:
115+
case E_RECOVERABLE_ERROR:
116+
break;
117+
default:
118+
return;
119+
}
120+
121+
$this->exitCode = 1;
122+
$msg = "{$err["message"]} in {$err["file"]} on line {$err["line"]}";
123+
124+
$previous = Loop::get();
125+
126+
try {
127+
Loop::set((new Loop\DriverFactory)->create());
128+
Loop::run(function () use ($msg) {
129+
$this->logger->critical($msg);
130+
yield from $this->stop();
131+
});
132+
} finally {
133+
Loop::set($previous);
134+
}
133135
} finally {
134-
Loop::set($previous);
136+
$this->exit();
135137
}
136138
});
137139
}

0 commit comments

Comments
 (0)