Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Conversation

jkotalik
Copy link
Contributor

@jkotalik jkotalik commented Jul 13, 2017

Remove nulling out fields in favor of a dispose boolean.
Fixes #540

}
}

Copy link
Contributor

@moozzyk moozzyk Jul 13, 2017

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.

@Tratcher
Copy link
Member

Titles need a description.

@jkotalik jkotalik changed the title Fixes #540 Add boolean dispose flag in HttpRequestStreamReader #540 Jul 13, 2017
@jkotalik jkotalik changed the title Add boolean dispose flag in HttpRequestStreamReader #540 Add boolean dispose flag in HttpRequestStreamReader [#540] Jul 13, 2017
@jkotalik jkotalik removed the request for review from ryanbrandenburg July 13, 2017 22:25
@jkotalik jkotalik changed the title Add boolean dispose flag in HttpRequestStreamReader [#540] Add boolean dispose flag in HttpRequestStreamReader (#540) Jul 14, 2017
@Tratcher
Copy link
Member

let's do the response stream as well, and check if any other near by components have the same problem.

@jkotalik
Copy link
Contributor Author

🆙 📅 based on what @Tratcher mentioned. Also added tests and modified both files to be consistent.

@jkotalik jkotalik changed the title Add boolean dispose flag in HttpRequestStreamReader (#540) Add boolean dispose flag in HttpRequestStreamReader/ResponseWriter (#540) Jul 15, 2017
@Tratcher Tratcher added this to the 2.1.0 milestone Jul 17, 2017
@Tratcher Tratcher requested a review from rynowak July 17, 2017 16:24
if (_charBuffer != null)
{
_charPool.Return(_charBuffer);
_charBuffer = null;
Copy link
Member

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)
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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()
Copy link
Member

Choose a reason for hiding this comment

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

zero

@dnfclas
Copy link

dnfclas commented Jul 17, 2017

@jkotalik, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, .NET Foundation Pull Request Bot

if (_disposed)
{
throw new ObjectDisposedException("stream");
throw new ObjectDisposedException(nameof(HttpRequestStreamReader));
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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))]
Copy link
Contributor

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.

@Eilon
Copy link
Contributor

Eilon commented Jul 19, 2017

Would it make sense to add tests that check for ObjectDisposedException? If that's a "feature" of this type, should we not test it?

@jkotalik
Copy link
Contributor Author

Sounds reasonable, I'll add some in.

@jkotalik
Copy link
Contributor Author

@Tratcher @Eilon 🆙 📅 . I don't believe the async version can be tested in Assert.Throws, but please correct me if I'm wrong.

@Tratcher
Copy link
Member

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 () =>
Copy link
Member

@Tratcher Tratcher Jul 27, 2017

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)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor

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()
Copy link
Member

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.

@jkotalik jkotalik force-pushed the jkotalik/Dispose branch 2 times, most recently from d6c9f0c to 239c22d Compare July 27, 2017 19:47
@jkotalik
Copy link
Contributor Author

jkotalik commented Jul 27, 2017

@Eilon this good to go? 😄

@jkotalik jkotalik merged commit 057fc81 into dev Jul 27, 2017
@jkotalik jkotalik deleted the jkotalik/Dispose branch July 27, 2017 22:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants