Skip to content
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

IndexOutOfRangeException in WaitForSelectorAsync #1614

Closed
dhirensham opened this issue Jan 18, 2021 · 1 comment
Closed

IndexOutOfRangeException in WaitForSelectorAsync #1614

dhirensham opened this issue Jan 18, 2021 · 1 comment

Comments

@dhirensham
Copy link

Description

Occasionally and randomly (I cannot reliably reproduce this), I get an Index Out Of Range exception when calling WaitForSelectorAsync.

Complete minimal example reproducing the issue

                    await page.WaitForSelectorAsync("#selector", new WaitForSelectorOptions()
                    {
                        Timeout = 10000,
                        Visible = true,
                    });

Expected behavior:

Either a WaitTaskTimeoutException if the selector isn't available, or execution to resume normally.

Actual behavior:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Collections.Generic.List`1.Add(T item)
   at PuppeteerSharp.WaitTask..ctor(DOMWorld world, String predicateBody, Boolean isExpression, String title, WaitForFunctionPollingOption polling, Nullable`1 pollingInterval, Int32 timeout, Object[] args)
   at PuppeteerSharp.DOMWorld.<WaitForSelectorOrXPathAsync>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at PuppeteerSharp.Frame.<WaitForSelectorAsync>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at mycode

Versions

PuppeteerSharp 2.0.4
.net Framework 4.7.2

Additional Information

From browsing the source, the only List.Add call in the WaitTask constructor is at

_world.WaitTasks.Add(this);

That doesn't seem likely to throw so perhaps another race condition similar to #717 ?

@gmackiewicz
Copy link

I stumbled upon the exact same problem. It seems like there is a problem with using a List (which is not thread-safe) in a concurrent environment and we experience a race.

Are there any plans to address the issue?

@kblok kblok closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants