Skip to content

Commit

Permalink
Fix Race conditions on Page.CloseAsync (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Jan 4, 2019
1 parent b9688e0 commit 3c093e4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/PuppeteerSharp/Page.cs
Expand Up @@ -46,6 +46,7 @@ public class Page : IDisposable
private PageGetLayoutMetricsResponse _burstModeMetrics;
private bool _screenshotBurstModeOn;
private ScreenshotOptions _screenshotBurstModeOptions;
private TaskCompletionSource<bool> _closeCompletedTcs = new TaskCompletionSource<bool>();

private static readonly Dictionary<string, decimal> _unitToPixels = new Dictionary<string, decimal> {
{"px", 1},
Expand Down Expand Up @@ -80,6 +81,7 @@ public class Page : IDisposable
{
Close?.Invoke(this, EventArgs.Empty);
IsClosed = true;
_closeCompletedTcs.TrySetResult(true);
});

Client.MessageReceived += Client_MessageReceived;
Expand Down Expand Up @@ -1057,7 +1059,7 @@ public Task CloseAsync(PageCloseOptions options = null)
}

_logger.LogWarning("Protocol error: Connection closed. Most likely the page has been closed.");
return Target.CloseTask;
return _closeCompletedTcs.Task;
}

/// <summary>
Expand Down

0 comments on commit 3c093e4

Please sign in to comment.