Repository navigation
PAM Native 1.42.1
PAM Native 1.42.1 is an Android and iOS host fix: a PHP error can no longer end the app process. The PHP SDK, protocol and engine are the same as in 1.42.0. Only the version number changes for them.
The crash. Some PHP errors cannot be turned into an exception, such as an exhausted memory_limit, E_USER_ERROR or a compile error. When one of them, an exception that escaped the runtime, or a call to exit()/die() happened outside the app entry (in an event handler, render, cycle collection or shutdown), it reached zend_bailout() with no bailout address. PHP then called exit(-1). The app died with code 255, and the C++ static destructors ran on the PHP thread while the render thread was still drawing. Logcat showed ~EglManager() leaked an EGL context, then FORTIFY pthread_mutex_lock called on a destroyed mutex. Zé Chat hit this during pull to refresh. Before this fix, the bridge's own "Unhandled PHP exception" reports could never run.
The fix. The Android and iOS bridges now run every PHP entry point of the worker under a bailout guard. When PHP abandons a request, the bridge:
- reports it as a fatal
PAMERR1error (PHP Fatal error,PHP Parse errororPHP exit, phaseterminated) with PHP's message, file and line; - ends that request at once, which frees its memory;
- drops the events queued for it;
- waits for the next reload.
Debug builds open the error inspector, where Reload starts a fresh request. Release builds retry with backoff, then show the friendly fallback. Closing a failed runtime shuts PHP down cleanly, so the next runtime in the process can boot again. The bridges also detect a fatal error or exit() in the app entry: php_execute_script() returns bool, so the old FAILURE comparison never matched. They now check that the optional Runtime::checkpointHotReload() and shutdown() methods exist before calling them.
Validation on candidate 5488f7fb (based on v1.42.0):
- Reproduced on an x86_64 API 36 emulator with the 1.42.0 bridge:
exit()or an exception escaping the runtime in an event handler givesZygote: Process ... exited cleanly (255), the same exit code as in the field. - With the fix, the new
PamPhpFatalRecoveryInstrumentedTestpasses 6 of 6. It coversexit(), memory exhaustion and an escaping exception in an event, memory exhaustion andexit()in the entry, and closing a failed runtime. In each case there is exactly one fatal report, the process survives and the next reload runs. - 303 Android JVM tests pass.
- All 325 Android instrumented tests pass on API 36, run one class at a time, with no failures.
- 235 Rust tests pass, and
cargo fmt --checkis clean. The PHP SDK suite and protocol parity pass. The newscripts/test_php_bailout_guard.py(now in CI) checks that every PHP call in the worker is guarded and that Android and iOS share the same guard code. - The Linux CLI, Android renderer, PHP SDK archives and the plugin AAR rebuild deterministically and pass the package budgets.
Known limits:
- I compiled the iOS bridge with clang and the PHP 8.5 headers. Its XCTest (
testBridgeBailoutReportsAreFatal) is included, but Xcode/iOS execution was not available on Linux. - The
~EglManager/FORTIFY lines are a race with the render thread. I did not reproduce them on the emulator. The exit code and the PHP-thread exit path match the field crash. - This release does not fix the underlying PHP error in Zé Chat. With this release, it shows up in the error inspector (debug) or in the
PamNativeErrorslogcat tag (release) instead of killing the app.