microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

[Bug]: NullReferenceException on BrowserContext.NewPageAsync() #1777

Closed fr4gles closed 2 years ago

fr4gles commented 3 years ago

Playwright version

1.15.2

Operating system

Windows

What browsers are you seeing the problem on?

Chromium

Other information

What happened? / Describe the bug

Invoking await browser.NewContextAsync() rarely produces NullReferenceException.

It randomly happens on simplified flow:

  1. Create playwright -> browser -> context -> page
  2. Execute business logic / tests
  3. Close & Dispose page -> context -> browser -> playwright

Stacktrace:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Playwright.Transport.Converters.ChannelToGuidConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, Type returnType, JsonSerializerOptions options)
   at Microsoft.Playwright.Transport.Connection.SendMessageToServerAsync[T](String guid, String method, Object args)
   at Microsoft.Playwright.Core.BrowserContext.NewPageAsync()

Code snippet to reproduce your bug

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
await using context = await browser.NewContextAsync(<options>);
var page = await context.NewPageAsync();
// ... logic

Relevant log output

No response

mxschmitt commented 2 years ago

Are you still able to reproduce this? We run this code a few thousand times per CI run, and never received this exception.

fr4gles commented 2 years ago

Because of random nature of this exception I'm not able to prepare minimal repro code for this. But it still happens time to time. As our observations shows, it happens mainly on long running app - when code (like mentioned snipped) was run many times on long lived app.

It looks like some problem related to thread race, even we are not mixing instance usage on different threads.

mxschmitt commented 2 years ago

Closing as part of the triage process and we don't have a repro for it. Feel free to open a new issue if you have a repro, thanks!

SPPlaywright commented 7 months ago

Message: TestCleanup method XXX.XXX.BrowserTearDown threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not set an instance of an object..... Stack Trace: PLaywrightTest.get TestOK() Line 127 BrowserTest.BrowserTearDonw()