Skip to content

Fix null reference exception for Streaming null object #14004

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
Sep 26, 2019

Conversation

Kahbazi
Copy link
Member

@Kahbazi Kahbazi commented Sep 15, 2019

Fixes #13191

@BrennanConroy BrennanConroy added the area-signalr Includes: SignalR clients and servers label Sep 16, 2019
@BrennanConroy BrennanConroy changed the title Fix null reference exception for SignalR JavaScript Client Fix null reference exception for Streaming null object Sep 16, 2019
@BrennanConroy
Copy link
Member

Thanks for the PR @Kahbazi!

Unfortunately I think the fix is a little more complicated than this.

Now if someone passes null as an argument they'll fall through to the if statement that says // This should never happen, we instead would want the argument to be set on the arguments array.

Also, we should add a test to verify that the scenario is fixed and that we don't regress it in the future! The test would likely be similar to https://github.com/aspnet/AspNetCore/blob/7b0b2980dc6ffb860f2bcd71868d98d85c7d35b6/src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs#L3524

@Kahbazi
Copy link
Member Author

Kahbazi commented Sep 16, 2019

@BrennanConroy If it's possible I'd like to give it another try to fix this.
I have couple of question

  • This was the original javascript which causes the exception

this.hubConnection.stream("LogIn", username, passwordHash, location.origin, null).subscribe(...)

and the workaround was to put an empty string instead of null

this.hubConnection.stream("LogIn", username, passwordHash, location.origin, "").subscribe(...)

Shouldn't the correct way to use javascript client to just omit the last parameter?

this.hubConnection.stream("LogIn", username, passwordHash, location.origin).subscribe(...)

  • If I'm not wrong the current code has a bug whether the null is sent for cancellation token or any parameter so What should happen when there's a null argument for types like int, bool, DateTime? Should I put the default value on the arguments array or throw an exception?

  • What should happen if the number of arguments coming from client doesn't match the number on the server?

@BrennanConroy
Copy link
Member

If it's possible I'd like to give it another try to fix this.

Of course! I was just giving suggestions so that we can approve and merge this.

Shouldn't the correct way to use javascript client to just omit the last parameter?

No, in this case their method was public ChannelReader<ApiTypedData<LogInResponseType>> LogIn(string username, byte[] passwordHash, string baseUrl, string fastLoginPassword, CancellationToken cancellationToken) so they want to pass 4 arguments (userName, passwordHash, location.origin, and null).

What should happen when there's a null argument for types like int, bool, DateTime? Should I put the default value on the arguments array or throw an exception?

That should be handled by the underlying protocol.

What should happen if the number of arguments coming from client doesn't match the number on the server?

Also handled by the underlying protocol.

@Kahbazi
Copy link
Member Author

Kahbazi commented Sep 17, 2019

No, in this case their method was public ChannelReader<ApiTypedData> LogIn(string username, byte[] passwordHash, string baseUrl, string fastLoginPassword, CancellationToken cancellationToken) so they want to pass 4 arguments (userName, passwordHash, location.origin, and null).

Oh my bad, I was miscounting and thought the last parameter (null) was for cancellation token. Everything makes much more sense now.

Add unit test
@analogrelay analogrelay added this to the 5.0.0-preview1 milestone Sep 24, 2019
Copy link
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I want to give this a quick local test before merging and give @halter73 a chance to take a look if he'd like.

}
}


Copy link
Member

Choose a reason for hiding this comment

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

nit: remove this extra line

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChannelReader<T> method in Hub with CancellationToken throws
4 participants