Fix LspFraming permanently poisoning the stream on stray non-LSP output#106
Open
poman wants to merge 1 commit into
Open
Fix LspFraming permanently poisoning the stream on stray non-LSP output#106poman wants to merge 1 commit into
poman wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #105
LspFraming::extractOneMessage()threwInvalidArgumentException('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 strayconsole.logfrom a dependency, anything writing to fd 1 — permanently poisoned the framed stream: every subsequentsendAndReceive()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 nextContent-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
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 noContent-Length:marker at all, and skipping a malformedContent-Lengthvalue. Verified 3 of the 6 fail with the originalInvalidArgumentExceptionagainst the pre-fix code and all 6 pass with the fix.php-cs-fixer --dry-runclean;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.