Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Don't Flush read-only streams from CryptoStream - #27326 #27327

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void FlushFinalBlock()
innerCryptoStream.FlushFinalBlock();
}
}
else
else if (_canWrite)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A FileStream opened in read mode still has semantic behaviors on Flush, and not calling it could have observable consequences to caller code (and that was simply the first kind of stream I looked at). I don't know that there's a safe way to make this change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, basically, you are telling that my issue (CryptoStream throwing exceptions in Dispose) is a bug in Kestrel server that doesn't allow to call Flush on read-only stream, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sorry. If they can't/won't fix it you could add yet another Stream as a wrapper over it, which just intercepts the call to Flush and doesn't pass it on.

I checked the .NET Framework 2.0 source base, and CryptoStream definitely had this behavior back that far.

{
_stream.Flush();
}
Expand Down