Skip to content

Commit 228426f

Browse files
CopilotTyrrrz
andauthored
Fix concurrent HtmlParser corruption by removing static singleton (#956)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com>
1 parent a0daac2 commit 228426f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

YoutubeExplode/Utils/Html.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ namespace YoutubeExplode.Utils;
55

66
internal static class Html
77
{
8-
private static readonly HtmlParser HtmlParser = new();
9-
10-
public static IHtmlDocument Parse(string source) => HtmlParser.ParseDocument(source);
8+
// A new HtmlParser instance must be created for each call to avoid thread safety issues
9+
// when multiple YoutubeClient instances are used concurrently. HtmlParser is not thread-safe
10+
// and sharing a single static instance causes corruption errors (InvalidOperationException)
11+
// in AngleSharp's internal collections.
12+
// https://github.com/Tyrrrz/YoutubeExplode/issues/955
13+
public static IHtmlDocument Parse(string source) => new HtmlParser().ParseDocument(source);
1114
}

0 commit comments

Comments
 (0)