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
Mosquitto bridge problem due to non blocking socket connect #478
Comments
Could you please try this again with 1.4.14? Setting the bridge to be a blocking connect isn't a great solution I'm afraid. |
Hello, |
My solution: |
I have this same thing happening for 1.4.14. Windows 7 x64 and Windows 10. |
I have mosquitto_net_write for the CONNECT returning -1 and WSAGetLastError giving 10057 (WSAENOTCONN). This allows the CONNECT to proceed:
|
This is fixed for 1.6.5, thanks for the hints. |
Hello,
I was creating a Mosquitto bridge on Windows 7 x64 system.
By using the latest stable build of installer mosquitto-1.4.12-install-win32.exe I was getting the following error
After checking the code I found that the statement in bridge.c at line number 368 as follows, makes a non blocking socket connect.
rc = _mosquitto_socket_connect(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, false);
So the the next command on line 387 sometimes fails, since the connection has not been established, as the previous connect is non-blocking. In other word the command below is executed before the previous command has succeeded in making the socket connection.
rc = _mosquitto_send_connect(context, context->keepalive, context->clean_session);
As a quick workaround I had put a Sleep statement previous to line 387, so as to allow some time for the connection, however the the time taken for connect was depending on the speed of the network connection, as for a slower network it took more time and the duration for Sleep was not constant. So in some cases the bridge connection was failing where the network is slow.
Another solution which I made was to change line no. 368 as
rc = _mosquitto_socket_connect(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, true);
where now the socket connection is a blocking connect. And this solution worked, even if the network was slow.
I wanted to know if the second solution which I have provided is a proper one, or is there a better method to solve the problem. I suppose that originally the socket connection may have be done as non-blocking for some specific purpose.
Thanks
The text was updated successfully, but these errors were encountered: