fix: copy the config on browser creation instead of mutating the caller's - #82
Merged
Merged
Conversation
…er's DefaultBrowser.start() resolves runtime state onto the Config it is handed: it assigns host and port, and appends launch arguments. Reusing the same Config instance for a second browser therefore made start() take its connectExisting branch, where it never launches a browser process and only tries to reach the previous one's now-dead port. The retry could not succeed, and logged "Browser process started with PID: null" while burning a full connect window. DefaultBrowser now works on its own copy, so callers can safely reuse a Config — including to retry a failed start. Config.copy() duplicates the argument and extension lists, passes the already resolved executable path so the copy does not re-run the disk search, and copies the userDataDir backing field rather than the getter, which would otherwise materialise a temporary profile directory on a config that may never be started.
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.
Problem
DefaultBrowser.start()writes runtime state onto theConfigit is given — it assignshostandport, and appends launch arguments:So passing the same
Configto a second browser makes it take theconnectExistingbranch: it never launches a browser process, and only tries to reach the previous one's port, which is dead by then. The start then fails after the full connect window, loggingBrowser process started with PID: null.This bites anyone retrying a failed start with the same config, which is a natural thing to do.
Fix
DefaultBrowsernow works on its own copy:Copying rather than making
Configimmutable keeps this a small, non-breaking change:browser.config.portstill returns the port actually in use, and no public API changes shape.Config.copy()is deep where it matters, with three details worth noting:browserExecutablePath, so the copy does not re-run the executable disk search;userDataDirbacking field rather than the getter — reading the getter would materialise a temporary profile directory on a config that may never be started.Tests
Three tests on
Config.copy(): independence of args/host/port, no duplication of the default arguments across repeated copies, and correctuserDataDirhandling in both the custom and default cases.ConfigDslTest.testCreateBrowserWithDslConfigassertedassertEquals(cfg, browser.config), which encoded the old instance-sharing behaviour. It now asserts the stronger contract: the browser holds a distinct copy, the values carry over, and the caller's config is left untouched (cfg.portstays null whilebrowser.config.portis set).Note:
:core:buildfails onkotlinStoreYarnLockon this branch, but it does so onmaintoo — unrelated to this change.:core:jvmTestpasses.