Skip to content

Commit 93fdf57

Browse files
authored
[dotnet] [bidi] Give only one chance to receive from remote end (#16360)
1 parent b3b66a0 commit 93fdf57

File tree

1 file changed

+20
-8
lines changed
  • dotnet/src/webdriver/BiDi/Communication

1 file changed

+20
-8
lines changed

dotnet/src/webdriver/BiDi/Communication/Broker.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,33 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
123123

124124
private async Task ReceiveMessagesAsync(CancellationToken cancellationToken)
125125
{
126-
while (!cancellationToken.IsCancellationRequested)
126+
try
127127
{
128-
try
128+
while (!cancellationToken.IsCancellationRequested)
129129
{
130130
var data = await _transport.ReceiveAsync(cancellationToken).ConfigureAwait(false);
131131

132-
ProcessReceivedMessage(data);
133-
}
134-
catch (Exception ex)
135-
{
136-
if (cancellationToken.IsCancellationRequested is not true && _logger.IsEnabled(LogEventLevel.Error))
132+
try
137133
{
138-
_logger.Error($"Couldn't process received BiDi remote message: {ex}");
134+
ProcessReceivedMessage(data);
139135
}
136+
catch (Exception ex)
137+
{
138+
if (_logger.IsEnabled(LogEventLevel.Error))
139+
{
140+
_logger.Error($"Unhandled error occured while processing remote message: {ex}");
141+
}
142+
}
143+
}
144+
}
145+
catch (Exception ex) when (ex is not OperationCanceledException)
146+
{
147+
if (_logger.IsEnabled(LogEventLevel.Error))
148+
{
149+
_logger.Error($"Unhandled error occured while receiving remote messages: {ex}");
140150
}
151+
152+
throw;
141153
}
142154
}
143155

0 commit comments

Comments
 (0)