Skip to content

Commit

Permalink
chore(connection): add close reason to connection closed exception (#…
Browse files Browse the repository at this point in the history
…1032)

* chore(connection): add close reason to connection closed exception

* Don't overwrite the reason

* Change to connection disposed

* Check for null

* Check connection closed

* should be not

* swallow
  • Loading branch information
kblok committed Dec 3, 2020
1 parent ececc05 commit e45ef99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/PlaywrightSharp/Selectors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ public async Task RegisterAsync(string name, string script = null, string path =
tasks.Add(channel.RegisterAsync(registerParam));
}

await Task.WhenAll(tasks).ConfigureAwait(false);
try
{
await Task.WhenAll(tasks).ConfigureAwait(false);
}
catch (Exception ex) when (ex.Message.Contains("Connection closed"))
{
// Ignore connection closed exceptions.
}

_registrations.Add(registerParam);
}
Expand All @@ -66,8 +73,9 @@ internal async Task AddChannelAsync(SelectorsOwner channel)
{
await Task.WhenAll(tasks).ConfigureAwait(false);
}
catch
catch (Exception ex) when (ex.Message.Contains("Connection closed"))
{
// Ignore connection closed exceptions.
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/PlaywrightSharp/Transport/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ internal static async Task InstallAsync(string driverPath = null, string browser
{
if (IsClosed)
{
throw new PlaywrightSharpException("Connection closed");
throw new PlaywrightSharpException($"Connection closed ({_reason})");
}

int id = Interlocked.Increment(ref _lastId);
Expand Down Expand Up @@ -439,7 +439,7 @@ private void CreateRemoteObject(string parentGuid, ChannelOwnerType type, string

private void Close(string reason)
{
_reason = reason;
_reason = string.IsNullOrEmpty(_reason) ? reason : _reason;
if (!IsClosed)
{
foreach (var callback in _callbacks)
Expand Down Expand Up @@ -518,7 +518,7 @@ private void Dispose(bool disposing)
}

_queue.Dispose();
_transport.Close("Connection closed");
_transport.Close("Connection disposed");

try
{
Expand Down

0 comments on commit e45ef99

Please sign in to comment.