Skip to content

Set transport handlers earlier in Typescript client #12524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 27, 2019
Merged

Conversation

BrennanConroy
Copy link
Member

Fixes https://github.com/aspnet/AspNetCore-Internal/issues/2817

We were setting the handlers after start so there were a couple races.

One where data could be received from the server before the handlers were set and so they would be missed.
And another where stop could be called and cause a null ref on this.transport!.onreceive = this.onreceive; if it happened at the "right" time.

@BrennanConroy BrennanConroy added area-signalr Includes: SignalR clients and servers tell-mode Indicates a PR which is being merged during tell-mode labels Jul 24, 2019
@BrennanConroy BrennanConroy added this to the 3.0.0-preview8 milestone Jul 24, 2019
.on("GET", () => {
httpClientGetCount++;
if (httpClientGetCount === 1) {
if ((connection as any).transport.onreceive && (connection as any).transport.onclose) {
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a fragile way to test if the handlers are set considering it would fail if the private "transport" property gets renamed. Even the test name of "transport handlers set before start" seems overly specific to the implementation.

Can't we verify this in some more robust way? Like by sending a message as part of the first get response and ensuring the correct .on handler gets called?

Copy link
Member Author

Choose a reason for hiding this comment

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

This seems like a fragile way to test if the handlers are set considering it would fail if the private "transport" property gets renamed.

Says the guy that did (hubConnection as any).serverTimeout(); in tests!

Even the test name of "transport handlers set before start" seems overly specific to the implementation.

Not sure what you mean here, we're literally testing the specific implementation so...

Can't we verify this in some more robust way?

I couldn't find an easy way (read: any way) to test this without grabbing internal fields. In general we don't test race conditions unless there is a way to force the race to happen. In this case I found a way to force it but have to grab the internal fields to verify they were set. If it makes you happy I can just remove the test.

Like by sending a message as part of the first get response and ensuring the correct .on handler gets called?

That doesn't work because the real first response is after connect returns to HttpConnection and by then it's too late as we'll be past the race.

Copy link
Member

@halter73 halter73 Jul 24, 2019

Choose a reason for hiding this comment

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

Says the guy that did (hubConnection as any).serverTimeout(); in tests!

I was actually wondering if you would bring that up when I wrote this. I'm impressed you remembered 😄

Sometimes pragmatism beats purity. I didn't want to force a client test to wait for a server timeout to be exceeded just to pass. I'm a stickler for making tests run quickly, so I thought it was a good tradeoff.

If this really is too difficult to test any other way, I'm fine with it. I'm not entirely convinced that this is a hard to force race condition. You just need a transport that calls one of the callbacks prior to the start promise completion. That would probably be easiest with a mock transport inside a unit test.

Copy link
Member Author

Choose a reason for hiding this comment

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

You just need a transport that calls one of the callbacks prior to the start promise completion. That would probably be easiest with a mock transport inside a unit test.

So, we actually might want to have another test that does this, unfortunately it will hit a different code path than the main one as we check if someone passes in a custom ITransport and go down a different path for that case. But that doesn't help make this test nicer 😢

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine if we just test the custom ITransport in the unit test and leave this test as is.

@BrennanConroy
Copy link
Member Author

🆙 📅

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

My bad. I though I already approved this.

@BrennanConroy
Copy link
Member Author

@BrennanConroy
Copy link
Member Author

@aspnet-hello
Copy link

This comment was made automatically. If there is a problem contact [email protected].

I've triaged the above build. I've created/commented on the following issue(s)
https://github.com/aspnet/AspNetCore-Internal/issues/2772

@aspnet-hello
Copy link

This comment was made automatically. If there is a problem contact [email protected].

I've triaged the above build. I've created/commented on the following issue(s)
https://github.com/aspnet/AspNetCore-Internal/issues/2885

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers tell-mode Indicates a PR which is being merged during tell-mode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants