Skip to content

Commit 6af56b8

Browse files
authored
[Named Pipe] Check for pipe broken on WaitConnectionAsync (#46230)
1 parent 5ea213a commit 6af56b8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Servers/Kestrel/Transport.NamedPipes/src/Internal/NamedPipeConnectionListener.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ private async Task StartAsync(NamedPipeServerStream nextStream)
9494
}
9595
}
9696
}
97+
catch (IOException ex) when (!_listeningToken.IsCancellationRequested)
98+
{
99+
// WaitForConnectionAsync can throw IOException when the pipe is broken.
100+
NamedPipeLog.ConnectionListenerBrokenPipe(_log, ex);
101+
102+
// Dispose existing pipe, create a new one and continue accepting.
103+
nextStream.Dispose();
104+
nextStream = CreateServerStream();
105+
}
97106
catch (OperationCanceledException ex) when (_listeningToken.IsCancellationRequested)
98107
{
99108
// Cancelled the current token

src/Servers/Kestrel/Transport.NamedPipes/src/Internal/NamedPipeLog.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,6 @@ public static void ConnectionDisconnect(ILogger logger, NamedPipeConnection conn
7777
}
7878
}
7979

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

0 commit comments

Comments
 (0)