From a50e62de8580c844429ad680a374b8a4ea08179d Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 30 Sep 2025 21:10:59 +0300 Subject: [PATCH 1/5] [dotnet] [bidi] Give only one chance to receive from remote end --- .../src/webdriver/BiDi/Communication/Broker.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 3ad14385aa814..1dc6d938fa2fa 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -123,21 +123,23 @@ public async Task ConnectAsync(CancellationToken cancellationToken) private async Task ReceiveMessagesAsync(CancellationToken cancellationToken) { - while (!cancellationToken.IsCancellationRequested) + try { - try + while (!cancellationToken.IsCancellationRequested) { var data = await _transport.ReceiveAsync(cancellationToken).ConfigureAwait(false); ProcessReceivedMessage(data); } - catch (Exception ex) + } + catch (Exception ex) + { + if (cancellationToken.IsCancellationRequested is false && _logger.IsEnabled(LogEventLevel.Error)) { - if (cancellationToken.IsCancellationRequested is not true && _logger.IsEnabled(LogEventLevel.Error)) - { - _logger.Error($"Couldn't process received BiDi remote message: {ex}"); - } + _logger.Error($"Couldn't process received BiDi remote message: {ex}"); } + + throw; } } From 834decbf5b08541c2cbca99c2eb0eec565eb756c Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 30 Sep 2025 21:40:46 +0300 Subject: [PATCH 2/5] Update Broker.cs --- dotnet/src/webdriver/BiDi/Communication/Broker.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 1dc6d938fa2fa..98dfc4a6c4960 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -132,9 +132,9 @@ private async Task ReceiveMessagesAsync(CancellationToken cancellationToken) ProcessReceivedMessage(data); } } - catch (Exception ex) + catch (Exception ex) when (ex is not OperationCanceledException) { - if (cancellationToken.IsCancellationRequested is false && _logger.IsEnabled(LogEventLevel.Error)) + if (_logger.IsEnabled(LogEventLevel.Error)) { _logger.Error($"Couldn't process received BiDi remote message: {ex}"); } From 8ddd20528187b862f180548a939784a0b3aa99a3 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 30 Sep 2025 22:02:11 +0300 Subject: [PATCH 3/5] Adjust exception message --- dotnet/src/webdriver/BiDi/Communication/Broker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 98dfc4a6c4960..8b83b2803a989 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -136,7 +136,7 @@ private async Task ReceiveMessagesAsync(CancellationToken cancellationToken) { if (_logger.IsEnabled(LogEventLevel.Error)) { - _logger.Error($"Couldn't process received BiDi remote message: {ex}"); + _logger.Error($"Couldn't receive or process BiDi remote message: {ex}"); } throw; From ee1a0051658430dd6d728466e0abd53530842949 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 30 Sep 2025 22:14:41 +0300 Subject: [PATCH 4/5] But give a chance for commands and responses --- dotnet/src/webdriver/BiDi/Communication/Broker.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 8b83b2803a989..428783cb54f7d 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -129,14 +129,24 @@ private async Task ReceiveMessagesAsync(CancellationToken cancellationToken) { var data = await _transport.ReceiveAsync(cancellationToken).ConfigureAwait(false); - ProcessReceivedMessage(data); + try + { + ProcessReceivedMessage(data); + } + catch (Exception ex) + { + if (_logger.IsEnabled(LogEventLevel.Error)) + { + _logger.Error($"Unhandled error occured while process remote message: {ex}"); + } + } } } catch (Exception ex) when (ex is not OperationCanceledException) { if (_logger.IsEnabled(LogEventLevel.Error)) { - _logger.Error($"Couldn't receive or process BiDi remote message: {ex}"); + _logger.Error($"Unhandled error occured while receiving remote messages: {ex}"); } throw; From 5b27f2a0fb7495d5d203b4f4789c67e911fab4b8 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 30 Sep 2025 22:15:58 +0300 Subject: [PATCH 5/5] Update Broker.cs --- dotnet/src/webdriver/BiDi/Communication/Broker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 428783cb54f7d..77b592968b850 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -137,7 +137,7 @@ private async Task ReceiveMessagesAsync(CancellationToken cancellationToken) { if (_logger.IsEnabled(LogEventLevel.Error)) { - _logger.Error($"Unhandled error occured while process remote message: {ex}"); + _logger.Error($"Unhandled error occured while processing remote message: {ex}"); } } }