Repository navigation
Conversation
Preserve config-based logging on stdout through the existing logger singleton so PHPUnit process isolation cannot deadlock on a full stderr pipe. Keep DEBUG output and respect an already-applied logger.\n\nAdd logging regression coverage and document why the 0.5.10 invalid native boolean returns remain out of scope. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Exclude test-generated pact changes from the FFI upgrade. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Coverage Report for CI Build 37660029614Coverage increased (+0.003%) to 92.475%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
| ### Windows process isolation and Pact FFI 0.5.9 | ||
|
|
||
| Pact FFI 0.5.9 changed `pactffi_init_with_log_level` to write to stderr instead of | ||
| stdout. PHPUnit's process-isolation runner reads the child process's stdout to | ||
| EOF before draining stderr. On Windows, DEBUG logs can fill the stderr pipe: | ||
| the child blocks writing logs while PHPUnit waits for the child to finish. | ||
|
|
||
| Pact-PHP uses its existing logger singleton and an explicit stdout sink for | ||
| config-based logging. This preserves the previous logging destination and DEBUG | ||
| output without removing `--process-isolation`. An already-applied logger, such as | ||
| the file sink configured through the PHPUnit extension, is left unchanged. | ||
| The first applied logger determines the destination and level for the process. | ||
|
|
||
| The upgrade intentionally stops at 0.5.9. The published 0.5.10 Linux x86_64 library | ||
| was observed returning byte `2` instead of `0` on false-result paths, including | ||
| `pactffi_mock_server_matched` for a nonexistent server and `pactffi_with_body` for | ||
| an invalid handle. Both PHP FFI and Python ctypes interpret this as true. | ||
| Addressing those invalid native boolean returns is a separate upstream task; | ||
| the PHP assertions must not be weakened to hide them. |
There was a problem hiding this comment.
I think only 'Windows process isolation' worth mentioning. The 'Pact FFI 0.5.9 ' is only benefit maintainers of this library, I think users of this library doesn't want to know about this details. We already upgraded to 0.5.10 anyway. The description of this pull request already explain about it, so I'm fine with it.
So, I suggest to change to something like this:
| ### Windows process isolation and Pact FFI 0.5.9 | |
| Pact FFI 0.5.9 changed `pactffi_init_with_log_level` to write to stderr instead of | |
| stdout. PHPUnit's process-isolation runner reads the child process's stdout to | |
| EOF before draining stderr. On Windows, DEBUG logs can fill the stderr pipe: | |
| the child blocks writing logs while PHPUnit waits for the child to finish. | |
| Pact-PHP uses its existing logger singleton and an explicit stdout sink for | |
| config-based logging. This preserves the previous logging destination and DEBUG | |
| output without removing `--process-isolation`. An already-applied logger, such as | |
| the file sink configured through the PHPUnit extension, is left unchanged. | |
| The first applied logger determines the destination and level for the process. | |
| The upgrade intentionally stops at 0.5.9. The published 0.5.10 Linux x86_64 library | |
| was observed returning byte `2` instead of `0` on false-result paths, including | |
| `pactffi_mock_server_matched` for a nonexistent server and `pactffi_with_body` for | |
| an invalid handle. Both PHP FFI and Python ctypes interpret this as true. | |
| Addressing those invalid native boolean returns is a separate upstream task; | |
| the PHP assertions must not be weakened to hide them. | |
| ### Windows process isolation | |
| On Windows, running `composer run-examples` can randomly cause this error: | |
| > Script cd example/protobuf-sync-message/consumer && phpunit handling the run-example:protobuf-sync-message event returned with error code -1073741819 | |
| Script composer run-example:protobuf-sync-message handling the run-examples event returned with error code -1073741819 | |
| According to [Microsoft](https://learn.microsoft.com/en-us/answers/questions/379441/error-code-exited-with-code-1073741819#answer-379350): | |
| > it indicates that your program was terminated due to an access violation. This error can occur for a variety of reasons, including de-referencing a NULL pointer or referencing an invalid address. | |
| The solution is `composer run-examples:windows`. It attach option `--process-isolation`, which fixed this error. |
There was a problem hiding this comment.
Oh, now I realize that this pull request is not for https://github.com/pact-foundation/pact-php. Let me cherry pick some code to pact-foundation#829
There was a problem hiding this comment.
no need to cherry pick, might not be the right fix. thanks for looking Tien
Summary
--process-isolation; do not suppress logs or remove test isolation.docs/troubleshooting.md.This PR targets YOU54F/pact-php:master, not pact-foundation/pact-php.
Why Windows hangs
Investigated pact-foundation#829 and pact-foundation#830. Both Windows jobs stall in the very first binary consumer test after PHPUnit prints its configuration.
Pact FFI 0.5.9 changed
pactffi_init_with_log_levelfrom its default stdout writer to an explicit stderr writer:https://github.com/pact-foundation/pact-reference/blob/libpact_ffi-v0.5.9/rust/pact_ffi/src/lib.rs#L121
PHPUnit 11.5.57's process-isolation runner drains stdout to EOF before reading stderr:
https://github.com/sebastianbergmann/phpunit/blob/11.5.57/src/Util/PHP/JobRunner.php#L174
When DEBUG output fills the stderr pipe, the child blocks writing logs while PHPUnit waits for stdout EOF. This is a pipe deadlock, not a slow test.
The investigation reproduced the mechanism with native Pact calls, a bounded 4 KiB stderr pipe, and stdout-first reading: 0.5.8 completed, while 0.5.9 blocked until stderr was drained. A successful native binary-consumer probe moved about 6 KiB of output from stdout in 0.5.8 to stderr in 0.5.9.
The fix explicitly selects stdout through the existing logger API, preserving the documented pre-upgrade destination on all platforms. Repeated initialization is idempotent, and the first applied logger retains its destination and level.
Why not 0.5.10
The invalid native boolean returns are deliberately deferred to a separate upstream investigation/fix.
Direct Python ctypes probes against the published Linux x86_64 artifacts, bypassing PHP entirely, found:
pactffi_mock_server_matched(1234)for a nonexistent server002pactffi_with_body(0, Request, ...)for an invalid handle with a valid enum002PHP FFI and Python ctypes interpret byte
2as true. This accounts for the 11 false-result assertion failures and the V3/V4 compatibility failures taking the matched-server path for port0. ARM validation does not exhibit this behavior.The release compiler changed from Rust 1.98.1 to 1.99.0, which is an investigation lead, not a proven cause. This PR does not normalize invalid return bytes or weaken assertions.
Validation
Local validation on macOS ARM / PHP 8.5.10 with Pact FFI 0.5.9:
--process-isolation: passed.git diff --check: passed.Actual Windows verification is left to this fork's CI; the local machine is macOS.