You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The removal of Lazy initialization may introduce thread safety concerns if the BiDi class is accessed from multiple threads concurrently. The previous Lazy implementation provided thread-safe initialization, but direct field initialization in constructor doesn't guarantee thread-safe access to the modules themselves.
All modules are now initialized eagerly in the constructor regardless of whether they will be used. This could impact startup performance and memory usage, especially if some modules are rarely used or have expensive initialization.
Consider adding null checks or exception handling around module initialization. If any module constructor throws an exception, the BiDi object will be left in an inconsistent state with some modules initialized and others not.
-_sessionModule = new Session.SessionModule(_broker);-_browsingContextModule = new BrowsingContext.BrowsingContextModule(_broker);-_browserModule = new Browser.BrowserModule(_broker);-_networkModule = new Network.NetworkModule(_broker);-_inputModule = new Input.InputModule(_broker);-_scriptModule = new Script.ScriptModule(_broker);-_logModule = new Log.LogModule(_broker);-_storageModule = new Storage.StorageModule(_broker);+try+{+ _sessionModule = new Session.SessionModule(_broker);+ _browsingContextModule = new BrowsingContext.BrowsingContextModule(_broker);+ _browserModule = new Browser.BrowserModule(_broker);+ _networkModule = new Network.NetworkModule(_broker);+ _inputModule = new Input.InputModule(_broker);+ _scriptModule = new Script.ScriptModule(_broker);+ _logModule = new Log.LogModule(_broker);+ _storageModule = new Storage.StorageModule(_broker);+}+catch+{+ _broker?.Dispose();+ throw;+}
Apply / Chat
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies that if a module constructor fails, the _broker object might not be disposed, leading to a resource leak; the proposed try-catch block is a robust solution.
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
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.
User description
💥 What does this PR do?
Don't use
Lazy<T>because it reserves a reference to all modules, which is not AOT friendly.💡 Additional Considerations
Probably we want to make an initialization in Property (with locking to be thread-safe)?
🔄 Types of changes
PR Type
Other
Description
Remove
Lazy<T>initialization from BiDi modules for AOT compatibilityInitialize modules directly in constructor instead of lazy loading
Update property accessors to return modules directly
Changes diagram
Changes walkthrough 📝
BiDi.cs
Remove lazy initialization from BiDi modulesdotnet/src/webdriver/BiDi/BiDi.cs
Lazyfields with direct module fields.Value