@@ -577,7 +577,7 @@ private void FlushWrite(bool calledFromFinalizer)
577
577
#if USE_OVERLAPPED
578
578
if ( _isAsync )
579
579
{
580
- Task < int > writeTask = WriteInternalCoreAsync ( _buffer , 0 , _writePos , CancellationToken . None ) ;
580
+ Task writeTask = WriteInternalCoreAsync ( _buffer , 0 , _writePos , CancellationToken . None ) ;
581
581
// With our Whidbey async IO & overlapped support for AD unloads,
582
582
// we don't strictly need to block here to release resources
583
583
// since that support takes care of the pinning & freeing the
@@ -1394,7 +1394,7 @@ private Task WriteInternalAsync(byte[] array, int offset, int numBytes, Cancella
1394
1394
}
1395
1395
1396
1396
[ System . Security . SecuritySafeCritical ] // auto-generated
1397
- unsafe private Task < int > WriteInternalCoreAsync ( byte [ ] bytes , int offset , int numBytes , CancellationToken cancellationToken )
1397
+ private unsafe Task WriteInternalCoreAsync ( byte [ ] bytes , int offset , int numBytes , CancellationToken cancellationToken )
1398
1398
{
1399
1399
Debug . Assert ( ! _handle . IsClosed , "!_handle.IsClosed" ) ;
1400
1400
Debug . Assert ( _parent . CanWrite , "_parent.CanWrite" ) ;
@@ -1458,9 +1458,10 @@ unsafe private Task<int> WriteInternalCoreAsync(byte[] bytes, int offset, int nu
1458
1458
// For pipes, when they are closed on the other side, they will come here.
1459
1459
if ( errorCode == ERROR_NO_DATA )
1460
1460
{
1461
- // Not an error, but EOF. AsyncFSCallback will NOT be
1462
- // called. Call the user callback here .
1461
+ // Not an error, but EOF. AsyncFSCallback will NOT be called.
1462
+ // Completing TCS and return cached task allowing the GC to collect TCS .
1463
1463
completionSource . SetCompletedSynchronously ( 0 ) ;
1464
+ return Task . CompletedTask ;
1464
1465
}
1465
1466
else if ( errorCode != ERROR_IO_PENDING )
1466
1467
{
0 commit comments