@@ -254,9 +254,12 @@ public int ReadByte()
254254 {
255255 return _inputStream . ReadByte ( ) ;
256256 }
257- catch ( IOException )
257+ catch ( Exception ex )
258258 {
259- _isAlive = false ;
259+ if ( ex is IOException || ex is SocketException )
260+ {
261+ _isAlive = false ;
262+ }
260263
261264 throw ;
262265 }
@@ -270,9 +273,12 @@ public int ReadByteAsync()
270273 {
271274 return _inputStream . ReadByte ( ) ;
272275 }
273- catch ( IOException )
276+ catch ( Exception ex )
274277 {
275- _isAlive = false ;
278+ if ( ex is IOException || ex is SocketException )
279+ {
280+ _isAlive = false ;
281+ }
276282 throw ;
277283 }
278284 }
@@ -296,9 +302,13 @@ public async Task ReadAsync(byte[] buffer, int offset, int count)
296302 offset += currentRead ;
297303 shouldRead -= currentRead ;
298304 }
299- catch ( IOException )
305+ catch ( Exception ex )
300306 {
301- _isAlive = false ;
307+ if ( ex is IOException || ex is SocketException )
308+ {
309+ _isAlive = false ;
310+ }
311+
302312 throw ;
303313 }
304314 }
@@ -330,9 +340,12 @@ public void Read(byte[] buffer, int offset, int count)
330340 offset += currentRead ;
331341 shouldRead -= currentRead ;
332342 }
333- catch ( IOException )
343+ catch ( Exception ex )
334344 {
335- _isAlive = false ;
345+ if ( ex is IOException || ex is SocketException )
346+ {
347+ _isAlive = false ;
348+ }
336349 throw ;
337350 }
338351 }
@@ -369,9 +382,13 @@ public void Write(IList<ArraySegment<byte>> buffers)
369382 ThrowHelper . ThrowSocketWriteError ( _endpoint , status ) ;
370383 }
371384 }
372- catch ( IOException )
385+ catch ( Exception ex )
373386 {
374- _isAlive = false ;
387+ if ( ex is IOException || ex is SocketException )
388+ {
389+ _isAlive = false ;
390+ }
391+ _logger . LogError ( ex , nameof ( PooledSocket . Write ) ) ;
375392 throw ;
376393 }
377394 }
@@ -390,9 +407,12 @@ public async Task WriteAsync(IList<ArraySegment<byte>> buffers)
390407 ThrowHelper . ThrowSocketWriteError ( _endpoint ) ;
391408 }
392409 }
393- catch ( IOException ex )
410+ catch ( Exception ex )
394411 {
395- _isAlive = false ;
412+ if ( ex is IOException || ex is SocketException )
413+ {
414+ _isAlive = false ;
415+ }
396416 _logger . LogError ( ex , nameof ( PooledSocket . WriteAsync ) ) ;
397417 throw ;
398418 }
0 commit comments