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

Blocking accept in socketpair implementation may cause permanent hang after system resume from sleep #3144

Open
syou121 opened this issue Oct 25, 2024 · 2 comments
Labels
Component: libmosquitto Status: Available No one has claimed responsibility for resolving this issue.

Comments

@syou121
Copy link

syou121 commented Oct 25, 2024

Description:
On Windows platform, mosquitto may permanently hang when the system resumes from sleep state. After analysis, this issue occurs in the net__socketpair implementation.

Details:
In the current implementation, while the connect socket is set to non-blocking mode, the accept remains blocking
During system resume from sleep, when the network stack might not be fully initialized, the non-blocking connect may return EINPROGRESS or EWOULDBLOCK
The code proceeds to the blocking accept call, but since the connection might never complete, the accept call may block indefinitely

Affected Versions:
2.0.18 and later version

My Reproduce Experience:
After I wake up my Windows system, sometimes my program call "ondisconnect" callback. Then my program called "mosquitto_new" function and stuck in "net__socketpair function in lib/net_mosq.c" forever.

Related Code:

		if(net__socket_nonblock(&spR)){
			COMPAT_CLOSE(listensock);
			continue;
		}
		if(connect(spR, (struct sockaddr *)&ss, ss_len) < 0){
#ifdef WIN32
			errno = WSAGetLastError();
#endif
			**if(errno != EINPROGRESS && errno != COMPAT_EWOULDBLOCK)**{
				COMPAT_CLOSE(spR);
				COMPAT_CLOSE(listensock);
				continue;
			}
		}
		**spW = accept(listensock, NULL, 0);**
@syou121
Copy link
Author

syou121 commented Oct 25, 2024

Or maybe I use wrong method to reconnect... But I wonder if it is a question.

@ralight ralight added Component: libmosquitto Status: Available No one has claimed responsibility for resolving this issue. labels Oct 30, 2024
@syou121
Copy link
Author

syou121 commented Nov 4, 2024

I found my firewall caused the problem, because it banned "localhost" when waking up computer. But the blocking problem of MQTT still happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: libmosquitto Status: Available No one has claimed responsibility for resolving this issue.
Projects
None yet
Development

No branches or pull requests

2 participants