Skip to content

Commit 9ff9637

Browse files
committed
Fix GH-24787 delayed OOM during request startup
Fixes #24787.
1 parent 3efb356 commit 9ff9637

7 files changed

Lines changed: 81 additions & 22 deletions

File tree

‎.github/actions/apt-x32/action.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ runs:
99
OPCACHE_TLS_TESTS_DEPS="gcc clang lld"
1010
1111
export DEBIAN_FRONTEND=noninteractive
12-
dpkg --add-architecture i386
13-
apt-get update -y | true
12+
sudo dpkg --add-architecture i386
13+
sudo env DEBIAN_FRONTEND=noninteractive apt-get update -y | true
1414
# TODO: Reenable postgresql + postgresql-contrib packages once they work again.
15-
apt-get install -y \
15+
sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y \
1616
autoconf \
1717
bison \
1818
curl \

‎.github/actions/install-linux-x32/action.yml‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ runs:
55
- shell: bash
66
run: |
77
set -x
8-
make install
9-
mkdir -p /etc/php.d
10-
chmod 777 /etc/php.d
11-
echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini
12-
echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini
13-
echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini
14-
echo opcache.protect_memory=1 >> /etc/php.d/opcache.ini
15-
echo opcache.preload_user=root >> /etc/php.d/opcache.ini
8+
sudo make install
9+
sudo mkdir -p /etc/php.d
10+
sudo chmod 777 /etc/php.d
11+
echo mysqli.default_socket=/var/run/mysqld/mysqld.sock | sudo tee /etc/php.d/mysqli.ini > /dev/null
12+
echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock | sudo tee /etc/php.d/pdo_mysql.ini > /dev/null
13+
echo opcache.enable_cli=1 | sudo tee /etc/php.d/opcache.ini > /dev/null
14+
echo opcache.protect_memory=1 | sudo tee -a /etc/php.d/opcache.ini > /dev/null
15+
echo opcache.preload_user=root | sudo tee -a /etc/php.d/opcache.ini > /dev/null

‎.github/actions/test-linux/action.yml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ inputs:
99
jitType:
1010
default: 'disable'
1111
required: false
12-
idleCpu:
13-
default: 'false'
14-
required: false
1512
runs:
1613
using: composite
1714
steps:
@@ -50,7 +47,6 @@ runs:
5047
-d opcache.jit=${{ inputs.jitType }} \
5148
-d opcache.protect_memory=1 \
5249
-d opcache.jit_buffer_size=64M \
53-
${{ inputs.idleCpu == 'true' && '-j$(($(/usr/bin/nproc) - 1))' || '-j$(/usr/bin/nproc)' }} \
5450
-g FAIL,BORK,LEAK,XLEAK \
5551
--no-progress \
5652
--offline \

‎.github/workflows/test-suite.yml‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ jobs:
188188
${{ matrix.asan && '--asan' || '' }}
189189
${{ matrix.repeat && '--repeat 2' || '' }}
190190
${{ matrix.variation && '-d zend_test.observer.enabled=1 -d zend_test.observer.show_output=0' || '' }}
191-
idleCpu: ${{ matrix.asan && 'true' || 'false' }}
192191
- name: Test Tracing JIT
193192
if: ${{ inputs.all_variations || matrix.asan }}
194193
uses: ./.github/actions/test-linux
@@ -232,13 +231,11 @@ jobs:
232231
name: "LINUX_X32_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}"
233232
runs-on: ubuntu-24.04
234233
timeout-minutes: 180
235-
container:
236-
image: ubuntu:${{ fromJson(inputs.branch).config.ubuntu_version }}
237234
env:
238-
MYSQL_TEST_HOST: mysql
239-
PDO_MYSQL_TEST_DSN: mysql:host=mysql;dbname=test
240-
PDO_MYSQL_TEST_HOST: mysql
241-
PDO_FIREBIRD_TEST_DSN: firebird:dbname=firebird:test.fdb
235+
MYSQL_TEST_HOST: 127.0.0.1
236+
PDO_MYSQL_TEST_DSN: mysql:host=127.0.0.1;dbname=test
237+
PDO_MYSQL_TEST_HOST: 127.0.0.1
238+
PDO_FIREBIRD_TEST_DSN: firebird:dbname=localhost:test.fdb
242239
services:
243240
mysql:
244241
image: mysql:8.4

‎Zend/zend_API.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,6 +3418,10 @@ ZEND_API void zend_activate_modules(void) /* {{{ */
34183418
const zend_module_entry *module = *p;
34193419

34203420
if (module->request_startup_func(module->type, module->module_number)==FAILURE) {
3421+
/* Surface a delayed OOM before reporting a generic module startup failure. */
3422+
if (ZEND_HAS_OOM()) {
3423+
zend_handle_delayed_oom();
3424+
}
34213425
zend_error(E_WARNING, "request_startup() for %s module failed", module->name);
34223426
exit(1);
34233427
}

‎main/main.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,9 @@ zend_result php_request_startup(void)
19491949
/* PG(during_request_startup) = 0; */
19501950

19511951
php_hash_environment();
1952+
if (ZEND_HAS_OOM()) {
1953+
zend_handle_delayed_oom();
1954+
}
19521955
zend_activate_modules();
19531956
PG(modules_activated)=1;
19541957
} zend_catch {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
GH-24787 (Delayed OOM during request startup is handled as a fatal error)
3+
--SKIPIF--
4+
<?php
5+
if (!getenv('TEST_PHP_CGI_EXECUTABLE')) {
6+
die('skip php-cgi not available');
7+
}
8+
if (!extension_loaded('uri')) {
9+
die('skip uri extension not available');
10+
}
11+
?>
12+
--FILE--
13+
<?php
14+
$script = tempnam(sys_get_temp_dir(), 'gh24787');
15+
file_put_contents($script, "<?php echo \"request completed\\n\";");
16+
17+
// The field count needed to reach the startup gap varies by build and platform.
18+
$counts = range(1700, 1950, 4);
19+
$rinitFailed = false;
20+
$oomReported = false;
21+
foreach ($counts as $count) {
22+
$post = [];
23+
for ($i = 0; $i < $count; $i++) {
24+
$post[] = 'p' . $i . '=' . str_repeat('y', 4000);
25+
}
26+
$body = implode('&', $post);
27+
28+
$command = [
29+
getenv('TEST_PHP_CGI_EXECUTABLE'),
30+
'-n',
31+
'-d', 'memory_limit=8M',
32+
'-d', 'post_max_size=64M',
33+
'-d', 'max_input_vars=20000',
34+
'-d', 'html_errors=0',
35+
];
36+
$environment = [
37+
'REQUEST_METHOD' => 'POST',
38+
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
39+
'CONTENT_LENGTH' => (string) strlen($body),
40+
'SCRIPT_FILENAME' => $script,
41+
'REDIRECT_STATUS' => '1',
42+
];
43+
$process = proc_open($command, [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']], $pipes, null, $environment);
44+
fwrite($pipes[0], $body);
45+
fclose($pipes[0]);
46+
$output = stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]);
47+
fclose($pipes[1]);
48+
fclose($pipes[2]);
49+
proc_close($process);
50+
51+
$rinitFailed = $rinitFailed || str_contains($output, 'request_startup()');
52+
$oomReported = $oomReported || str_contains($output, 'Allowed memory size');
53+
}
54+
unlink($script);
55+
56+
echo !$rinitFailed && $oomReported ? "OOM handled\n" : "RINIT failure or no OOM reported\n";
57+
?>
58+
--EXPECT--
59+
OOM handled

0 commit comments

Comments
 (0)