-
Notifications
You must be signed in to change notification settings - Fork 191
Add boolean dispose flag in HttpRequestStreamReader/ResponseWriter (#540) #898
Conversation
} | ||
} | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(shameless plug) - install this: https://visualstudiogallery.msdn.microsoft.com/bcb3ef8e-a3a4-401e-9e63-fdf00b45268f and you won't make this mistake again.
Titles need a description. |
let's do the response stream as well, and check if any other near by components have the same problem. |
🆙 📅 based on what @Tratcher mentioned. Also added tests and modified both files to be consistent. |
if (_charBuffer != null) | ||
{ | ||
_charPool.Return(_charBuffer); | ||
_charBuffer = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these nulls as well.
_stream = null; | ||
|
||
_disposed = true; | ||
if (_bytePool != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are there null checks on _bytePool and _charPool here? The constructor prevents nulls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they were from before when we deliberately null out these streams.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except _bytePool wasn't being nulled out before.
} | ||
|
||
[Fact] | ||
public static void NegativeBufferSize_ExpectArgumentOutOfRangeException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zero
@jkotalik, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request. |
if (_disposed) | ||
{ | ||
throw new ObjectDisposedException("stream"); | ||
throw new ObjectDisposedException(nameof(HttpRequestStreamReader)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't pass anything into the ctor here. The type name is not the "object name" - it's pretty useless here and generates noise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObjectDisposedException doesn't actually have a ctor with no arguments. We seem to do the nameof(classname) across our repos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, that's fine. I looked through the CoreFX repo and in there it's a mix of null
, GetType().Name
, and other stuff like that. So nameof(this_class_name)
seems fine.
Assert.Null(eol); | ||
} | ||
|
||
[Theory, MemberData(nameof(HttpRequestStreamReaderData))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider putting the attributes on separate lines.
Would it make sense to add tests that check for |
Sounds reasonable, I'll add some in. |
59275fa
to
7a2c331
Compare
There's an Assert.ThrowsAsync |
var httpRequestStreamReader = new HttpRequestStreamReader(new MemoryStream(), Encoding.UTF8, 10, ArrayPool<byte>.Shared, ArrayPool<char>.Shared); | ||
httpRequestStreamReader.Dispose(); | ||
|
||
Assert.ThrowsAsync<ObjectDisposedException>(async () => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await this (and make the method public async Task
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functions below are already async. I don't understand the value in doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yield return new object[] { new Func<HttpResponseStreamWriter, Task>(async (httpResponseStreamWriter) => { await httpResponseStreamWriter.WriteAsync('a'); })};
|
||
[Theory] | ||
[MemberData(nameof(HttpRequestNullData))] | ||
public static void NullInputsInConstructor_ExpectArgumentNullException(Stream stream, Encoding encoding, ArrayPool<byte> bytePool, ArrayPool<char> charPool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are your test methods static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of them were static to begin with, should I change it in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can leave it for now, it's just odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
means the test class's ctor won't run. Of course, if there isn't one, that's no problem. As long as the test runs and it passes, it's probably good 😄
} | ||
|
||
[Fact] | ||
public static async void StreamDisposed_ExpectObjectDisposedExceptionAsync() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async Task, never async void.
d6c9f0c
to
239c22d
Compare
@Eilon this good to go? 😄 |
239c22d
to
057fc81
Compare
Remove nulling out fields in favor of a dispose boolean.
Fixes #540