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

WebSocketServer stops running after a while. getsockname failed after a successful accept(). #1174

Closed
geneotech opened this issue May 11, 2024 · 2 comments · Fixed by #1175
Closed

Comments

@geneotech
Copy link

geneotech commented May 11, 2024

Hello! I'm using WebSocketServer.cpp to implement a simple signalling server (running on Ubuntu 22.04) for my WebRTC-based game. Eventually, I always end up getting a fatal error on a call to ::getpeername right after accept()ing a new connection. It causes the server to shutdown and stop accepting new connections:

	if (::getpeername(mSock, reinterpret_cast<struct sockaddr *>(&addr), &addrlen) < 0)
		throw std::runtime_error("getsockname failed");

This is strange given that accept() should return a connected socket, and the previous calls to ::ioctlsocket and ::setsockopt succeed.

Verbose logs:

(nothing for ~14 minutes)
[02:15:53] rtc::impl::TcpTransport::TcpTransport@63: Initializing TCP transport with socket
[02:15:53] rtc::impl::WebSocketServer::runLoop@94: WebSocketServer: getsockname failed
[02:15:53] rtc::impl::WebSocketServer::runLoop@97: Stopped WebSocketServer
(nothing later)

(The last successful connection before that was 14 minutes ago)

This is usually after my signalling server works perfectly for a day or two having handled tens, hundreds of connections prior.
It's likely not a resource leak on my part since the logs show an exactly matching number of:

rtc::impl::WebSocket::WebSocket@41: Creating WebSocket

and:

rtc::impl::WebSocket::~WebSocket@65: Destroying WebSocket

Could this be a threading issue? I see that ::accept and the corresponding closesocket within TcpTransport are under different mutexes (first under mSockMutex and the latter under mSendMutex). I saw a similar issue here:
grpc/grpc#35076 (comment)

@paullouisageneau
Copy link
Owner

Thank you for reporting. I don't think this is a threading issue as getpeernameis called immediately and only the server thread manipulates the new incoming socket. It's possible that the socket is immediately closed.

The main issue is that such an error with an incoming connection should not make the whole server fail, it should be caught earlier.

@paullouisageneau
Copy link
Owner

It should be fixed by #1175

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