Skip to content

Fix LspFraming permanently poisoning the stream on stray non-LSP output#106

Open
poman wants to merge 1 commit into
playwright-php:mainfrom
poman:fix/lsp-framing-resync-stray-output
Open

Fix LspFraming permanently poisoning the stream on stray non-LSP output#106
poman wants to merge 1 commit into
playwright-php:mainfrom
poman:fix/lsp-framing-resync-stray-output

Conversation

@poman

@poman poman commented Jul 7, 2026

Copy link
Copy Markdown

Fixes #105

LspFraming::extractOneMessage() threw InvalidArgumentException('Missing or invalid Content-Length header') as soon as the receive buffer did not start with a valid frame header, and never resynced afterwards. Any stray output on the Node bridge stdout — a Chromium crash dump, a stray console.log from a dependency, anything writing to fd 1 — permanently poisoned the framed stream: every subsequent sendAndReceive() on that client threw, with no way to recover the session.

Fixes it by resyncing instead of throwing: when the current header block does not contain a valid Content-Length, skip forward to the next Content-Length: occurrence in the buffer and retry from there; if none is found yet, keep buffering. This is the same skip-to-next-header strategy LSP-based tooling (e.g. vscode-languageclient) uses for robustness against interleaved non-protocol output.

Testing

  • Added tests/Unit/Transport/JsonRpc/LspFramingTest.php (6 tests): normal single/multiple message decoding, buffering an incomplete message, resyncing past stray text before/between well-formed frames, buffering pure garbage with no Content-Length: marker at all, and skipping a malformed Content-Length value. Verified 3 of the 6 fail with the original InvalidArgumentException against the pre-fix code and all 6 pass with the fix.
  • Full test suite: 802/802 unit, 236/236 integration passing (2 pre-existing, unrelated deprecation warnings elsewhere).
  • php-cs-fixer --dry-run clean; phpstan analyse (level 10) reports 0 errors on the changed/added files.

Discovered while running the OroCommerce Behat regression suite on a driver built on top of this library: after a Chromium renderer crash, crash diagnostics ended up interleaved with the framed stream and every following scenario in that process failed with the same InvalidArgumentException, losing the rest of the run on that node.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stray non-LSP output on the bridge stdout permanently poisons the framed stream

1 participant