-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate Sobek and k6 logic from the module logic #271
Comments
This is also important to avoid data races from sharing |
What's on your mind doing so? :) |
Well, we currently pass xk6-browser/common/execution_context.go Line 180 in 3ad187c
Line 55 in 3ad187c
Instead, this should happen much higher up in the stack, as close as possible or inside the methods we already expose to JS, via this JS->Go translation layer. This way we should(?) ensure a single goroutine has access to the |
+1 That is exactly what I had in my mind: Goja should not enter into the extension logic realm. |
The previous way of waiting for navigation events had a couple of issues: - There was a race condition where the Page.frameNavigated CDP event was received before we had a chance to setup the waiter for it, causing timeouts (#272). - The implementation was repeated two times in FrameManager (NavigateFrame and WaitForNavigation). This change tries to setup the waiters concurrently with the FrameSession.navigateFrame call, which minimizes--but doesn't completely eliminate--the chance of a missed event and timeout. It also moves the implementation to Frame and reuses it for both Goto and WaitForNavigation. There's another version of this in Page.Reload which I didn't bother changing here. It also does the JS option parsing upfront in the functions exported to the script, so that internally we don't depend on goja.Runtime (part of #271). It's currently not possible to completely avoid the race, since there's no way to synchronize when the waiters are actually started (i.e. when the goroutine in createWaitForEventHandler is started). There's another issue with Page.Goto when it sometimes returns a nil Response. I tried fixing this by adding another waiter for EventPageResponse, but that turned out to be racy as well (e.g. on internal pages like about:blank or data URIs). Fixing these issues will require a major change in how events are handled internally. Closes #272
The previous way of waiting for navigation events had a couple of issues: - There was a race condition where the Page.frameNavigated CDP event was received before we had a chance to setup the waiter for it, causing timeouts (#272). - The implementation was repeated two times in FrameManager (NavigateFrame and WaitForNavigation). This change tries to setup the waiters concurrently with the FrameSession.navigateFrame call, which minimizes--but doesn't completely eliminate--the chance of a missed event and timeout. It also moves the implementation to Frame and reuses it for both Goto and WaitForNavigation. There's another version of this in Page.Reload which I didn't bother changing here. It also does the JS option parsing upfront in the functions exported to the script, so that internally we don't depend on goja.Runtime (part of #271). It's currently not possible to completely avoid the race, since there's no way to synchronize when the waiters are actually started (i.e. when the goroutine in createWaitForEventHandler is started). There's another issue with Page.Goto when it sometimes returns a nil Response. I tried fixing this by adding another waiter for EventPageResponse, but that turned out to be racy as well (e.g. on internal pages like about:blank or data URIs). Fixing these issues will require a major change in how events are handled internally. Closes #272
This was causing data races if the runtime was also being used by the event loop goroutine, since goja is not thread-safe. It also moves towards removing the dependency on goja from internal methods, which is what we're aiming for. A good rule of thumb to follow from now on is to never use goja on unexported methods, and only on those that are directly exposed to JS. Part of #271
This can also mitigate some of the known bugs caused by the concurrent Sobek usage throughout the extension 🤞
Runtime
is most needed because of Sobek conversions. If we can provide a translation layer between Sobek and the extension code, we can greatly simplify it. For example:This kind of cluttering happens because of internally exposing Sobek, whereas we could do:
See #268 (comment).
The text was updated successfully, but these errors were encountered: