Skip to content
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

[SignalR-Client-Cpp] Cannot properly handle invalid url #43774

Open
1 task done
Wasenshi123 opened this issue Sep 6, 2022 · 4 comments · May be fixed by aspnet/SignalR-Client-Cpp#94
Open
1 task done

[SignalR-Client-Cpp] Cannot properly handle invalid url #43774

Wasenshi123 opened this issue Sep 6, 2022 · 4 comments · May be fixed by aspnet/SignalR-Client-Cpp#94
Assignees
Labels
area-signalr Includes: SignalR clients and servers bug This issue describes a behavior which is not expected - a bug. feature-client-c++ Related to the SignalR C++ client
Milestone

Comments

@Wasenshi123
Copy link

Wasenshi123 commented Sep 6, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When use a url like "/something" then start the connection,

It seems that underline lib cpprest does not allow empty host and throw the exception, but the exception does not return in the callback, instead, it terminates the program.

terminate called after throwing an instance of 'std::invalid_argument'
  what():  URI must contain a hostname.
Aborted

and this cannot be catched in anyway because the function hub_connection::start(std::function<void(std::exception_ptr)> callback) noexcept; is a noexcept function

https://docs.microsoft.com/en-us/cpp/cpp/noexcept-cpp?view=msvc-170

Mark a function as noexcept only if all the functions that it calls, either directly or indirectly, are also noexcept or const. The compiler doesn't necessarily check every code path for exceptions that might bubble up to a noexcept function. If an exception does exit the outer scope of a function marked noexcept, std::terminate is invoked immediately, and there's no guarantee that destructors of any in-scope objects will be invoked.

Expected Behavior

With the mark of noexcept in hub_connection::start() function, any exceptions that might occur are expected to be in the callback.

Otherwise, it should not be marked with noexcept and let user handle any exception that might come out from it.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

@javiercn javiercn added the area-signalr Includes: SignalR clients and servers label Sep 6, 2022
@BrennanConroy BrennanConroy added the feature-client-c++ Related to the SignalR C++ client label Sep 6, 2022
@BrennanConroy
Copy link
Member

While we should probably fix the underlying issue, why are you trying to use /something? That won't work unless you're using the Javascript client in the browser since we can infer the current web pages host then.

@Wasenshi123
Copy link
Author

Wasenshi123 commented Sep 6, 2022

It's just my use case where the app is in initial state and the server url is not yet configured, so the url might be in that format at first use.

And since my app allow free input from user (to configure their server url), I will need to be able to catch/handle this exception appropriately.

@BrennanConroy
Copy link
Member

You could also look at the url before initializing the SignalR connection.

@Wasenshi123
Copy link
Author

You could also look at the url before initializing the SignalR connection.

Yes, that is my workaround right now.

But anyhow, would be nice if this is addressed from the lib itself.

@BrennanConroy BrennanConroy added the bug This issue describes a behavior which is not expected - a bug. label Sep 6, 2022
@rafikiassumani-msft rafikiassumani-msft added this to the 7.0.0 milestone Sep 6, 2022
@BrennanConroy BrennanConroy modified the milestones: 7.0.0, 9.0.0 Mar 4, 2024
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 bug This issue describes a behavior which is not expected - a bug. feature-client-c++ Related to the SignalR C++ client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@javiercn @BrennanConroy @Wasenshi123 @rafikiassumani-msft and others