Close CDP streams after reading - #609
Open
i7a wants to merge 3 commits into
Open
Conversation
Contributor
Author
|
Two behavior questions for maintainers:
|
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.
Summary
Close CDP streams with
IO.closeafter reading:Page.printToPDFTracing.tracingCompleteeventMotivation
Ferrum requests stream-based output from CDP for PDF generation and tracing.It reads each stream with
IO.readuntil EOF, but does not close the stream handle afterward.For PDF generation, the handle is returned by
Page.printToPDF. For tracing, the handle is delivered through theTracing.tracingCompleteevent afterTracing.endis called.CDP provides
IO.closeto release a stream handle and discard any temporary backing storage associated with it. Explicitly closing the stream after use keeps its lifecycle well-defined and avoids relying on implicit browser-side cleanup.This affects streams used by:
Ferrum::Browser#pdfFerrum::Page::Tracing#recordError handling
IO.closeis called from anensureblock, so cleanup is attempted when:IO.readfailsIf reading or writing has already failed, an
IO.closeerror is suppressed so that it does not replace the original exception.If the stream was read successfully, anIO.closeerror is propagated to the caller.Tests
Added unit tests covering:
IO.readfailuresStandardErrorexceptionsIO.closefailure after a successful read