Skip to content

Commit

Permalink
[Named Pipe] Check for pipe broken on WaitConnectionAsync (#46230)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Jan 25, 2023
1 parent 5ea213a commit 6af56b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ private async Task StartAsync(NamedPipeServerStream nextStream)
}
}
}
catch (IOException ex) when (!_listeningToken.IsCancellationRequested)
{
// WaitForConnectionAsync can throw IOException when the pipe is broken.
NamedPipeLog.ConnectionListenerBrokenPipe(_log, ex);

// Dispose existing pipe, create a new one and continue accepting.
nextStream.Dispose();
nextStream = CreateServerStream();
}
catch (OperationCanceledException ex) when (_listeningToken.IsCancellationRequested)
{
// Cancelled the current token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ public static void ConnectionDisconnect(ILogger logger, NamedPipeConnection conn
}
}

[LoggerMessage(8, LogLevel.Debug, "Named pipe listener received broken pipe while waiting for a connection.", EventName = "ConnectionListenerBrokenPipe")]
public static partial void ConnectionListenerBrokenPipe(ILogger logger, Exception ex);
}

0 comments on commit 6af56b8

Please sign in to comment.