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

WebSocket stuck in the Connecting state #842

Closed
aleksey-salow opened this issue Apr 3, 2023 · 3 comments · Fixed by #853
Closed

WebSocket stuck in the Connecting state #842

aleksey-salow opened this issue Apr 3, 2023 · 3 comments · Fixed by #853

Comments

@aleksey-salow
Copy link

Looks like a changeState(State::Failed); is required here:

} else {
PLOG_ERROR << "TLS handshake failed";
}

Found on version: 0.18.2 with OpenSSL
How to reproduce: run the WebSocket server with TLS enabled and autogenerated certificate. Try to connect to the server from Firefox or Chrome. Since modern browsers don't trust self-signed certificates by default, the connection will be rejected.
Observed behavior: client WebSocket stuck in the Connecting state
Expected behavior: onError or onClosed events are called.

2023-04-03 13:21:20.932 DEBUG [20392] [rtc::impl::TcpTransport::TcpTransport@49] Initializing TCP transport with socket
2023-04-03 13:21:20.933 DEBUG [20392] [rtc::impl::TlsTransport::TlsTransport@300] Initializing TLS transport (OpenSSL)
2023-04-03 13:21:20.934 DEBUG [20392] [rtc::impl::TlsTransport::start@377] Starting TLS recv thread
2023-04-03 13:21:20.968 ERROR [17464] [rtc::impl::TlsTransport::InfoCallback@491] TLS alert: bad certificate
2023-04-03 13:21:20.968 ERROR [17464] [rtc::impl::TlsTransport::runRecvLoop@481] TLS handshake failed

If continued attempts to establish a connection to the server, all the sockets still be registered in the PollService. At some point, PollService will fail. I tested on my Windows system, and ~70 connections were enough.

2023-04-03 13:32:25.787 FATAL [26280] [rtc::impl::PollService::runLoop@200] Poll service failed: poll failed, errno=10038
2023-04-03 13:32:25.787 DEBUG [26280] [rtc::impl::PollService::runLoop@203] Poll service stopped
@paullouisageneau
Copy link
Owner

Thank you for reporting, I added the missing state change in #845 which will indeed solve the main issue with WebSockets stuck in connecting state with OpenSSL.

The second issue with WinSock error 10038 (i.e. WSAENOTSOCK) in PollService::runLoop() is actually quite tricky. The code takes advantage of a borderline behavior of poll() in POSIX systems which can be called on closed file descriptors without error (it will only set POLLNVAL), while on Windows WSAPoll() may apparently fail in such a situation.

@aleksey-salow
Copy link
Author

The second issue is just a result of the first. Sockets from the failed connections are still registered in PollService. As I understand, after some timeout, Windows closes sockets, and WSAPoll() fails. It took around a minute on my dev machine to reproduce an issue. But anyway, the fix for the socket state also solves the WSAPoll() issue, so I think this is not a critical bug.

@paullouisageneau
Copy link
Owner

This is still a bug on Windows that could be triggered in another way. I'm pushing a workaround to prevent failure when WSAPoll() returns WSAENOTSOCK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants