Skip to content

Commit a360574

Browse files
suppress logging of expected cancellation errors during server shutdown
1 parent 1106f1d commit a360574

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/UiPath.CoreIpc/Config/IpcServer.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,21 @@ private async Task DisposeCore()
132132

133133
private async Task LoopAccept(CancellationToken ct)
134134
{
135-
try
135+
while (!ct.IsCancellationRequested)
136136
{
137-
while (!ct.IsCancellationRequested)
138-
{
139-
await Accept(ct);
140-
}
141-
}
142-
catch (OperationCanceledException ex) when (ex.CancellationToken == ct)
143-
{
144-
// Ignore
137+
await TryAccept(ct); /// this method doesn't throw, and in case of non-<see cref="OperationCanceledException"/> exceptions,
138+
/// it will notify the <see cref="_newConnection"/> observer.
145139
}
146140

147141
_newConnection.OnCompleted();
148142
}
149143

150-
private async Task Accept(CancellationToken ct)
144+
/// <summary>
145+
/// This method returns when a new connection is accepted, or when cancellation or another error occurs.
146+
/// In case of cancellation or error, it will dispose of the underlying resources and will suppress the exception.
147+
/// In case of an error (not a cancellation), it will notify the observer about the error.
148+
/// </summary>
149+
private async Task TryAccept(CancellationToken ct)
151150
{
152151
var slot = _serverState.CreateConnectionSlot();
153152

@@ -159,11 +158,14 @@ private async Task Accept(CancellationToken ct)
159158
var newConnection = await taskNewConnection;
160159
_newConnection.OnNext(newConnection);
161160
}
161+
catch (OperationCanceledException ex) when (ex.CancellationToken == ct)
162+
{
163+
await slot.DisposeAsync();
164+
}
162165
catch (Exception ex)
163166
{
164167
await slot.DisposeAsync();
165168
_newConnection.OnError(ex);
166-
return;
167169
}
168170
}
169171

0 commit comments

Comments
 (0)