Skip to content

Commit ecaf43b

Browse files
authored
Fix WaitTasks concurrency issues (#1698)
1 parent 054314b commit ecaf43b

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

lib/PuppeteerSharp/DOMWorld.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text;
45
using System.Threading.Tasks;
56
using Newtonsoft.Json.Linq;
@@ -16,7 +17,7 @@ internal class DOMWorld
1617
private TaskCompletionSource<ExecutionContext> _contextResolveTaskWrapper;
1718
private TaskCompletionSource<ElementHandle> _documentCompletionSource;
1819

19-
internal List<WaitTask> WaitTasks { get; set; }
20+
internal ICollection<WaitTask> WaitTasks { get; set; }
2021

2122
internal Frame Frame { get; }
2223

@@ -28,7 +29,7 @@ public DOMWorld(FrameManager frameManager, Frame frame, TimeoutSettings timeoutS
2829

2930
SetContext(null);
3031

31-
WaitTasks = new List<WaitTask>();
32+
WaitTasks = new ConcurrentSet<WaitTask>();
3233
_detached = false;
3334
}
3435

@@ -56,7 +57,7 @@ internal void Detach()
5657
_detached = true;
5758
while (WaitTasks.Count > 0)
5859
{
59-
WaitTasks[0].Terminate(new Exception("waitForFunction failed: frame got detached."));
60+
WaitTasks.First().Terminate(new Exception("waitForFunction failed: frame got detached."));
6061
}
6162
}
6263

lib/PuppeteerSharp/Frame.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public class Frame
4040
{
4141
private readonly CDPSession _client;
4242

43-
internal List<WaitTask> WaitTasks { get; }
44-
4543
internal string Id { get; set; }
4644

4745
internal string LoaderId { get; set; }
@@ -61,7 +59,6 @@ internal Frame(FrameManager frameManager, CDPSession client, Frame parentFrame,
6159
ParentFrame = parentFrame;
6260
Id = frameId;
6361

64-
WaitTasks = new List<WaitTask>();
6562
LifecycleEvents = new List<string>();
6663

6764
MainWorld = new DOMWorld(FrameManager, this, FrameManager.TimeoutSettings);

0 commit comments

Comments
 (0)