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
ConnectRetry
and AutoReconnect
do not work when connecting to docker host on MacOS
#597
Comments
This example demonstrates a bug in operation when attempting to connect/reconnect to an mqtt broker operating from the host machine. The changes I have made to the original project are as follows:
Standard operation (all working):Normal operationdocker-compose up Result: To demonstrate succesful reconnection when mqtt broker goes down then upIn terminal 1: docker-compose up In terminal 2:
Result: Succesful connection when services start without broker, then broker startsdocker-compose up In terminal 2:
Result: Using External Host:Normal OperationIn terminal 2: # Start the external broker
docker-compose -p mosquitto -f docker-compose.mosquitto.yml up -d In terminal 1: # Start pub and sub pointing at external broker
SERVERADDRESS=host.docker.internal:1883 docker-compose up Result: Unsuccesful reconnection when mqtt broker goes down then upIn terminal 2: # Start the external broker
docker-compose -p mosquitto -f docker-compose.mosquitto.yml up -d In terminal 1: # Start pub and sub pointing at external broker
SERVERADDRESS=host.docker.internal:1883 docker-compose up In terminal 2: # Stop the external broker
docker-compose -p mosquitto -f docker-compose.mosquitto.yml down
# Restart the external broker
docker-compose -p mosquitto -f docker-compose.mosquitto.yml up -d
Result: Both services display single reconnection message, but never recover (pub keeps publishing)
Failure to connect when services start without broker, then broker startsIn terminal 2: # Stop the external broker
docker-compose -p mosquitto -f docker-compose.mosquitto.yml down In terminal 1: # Start pub and sub pointing at external broker
SERVERADDRESS=host.docker.internal:1883 docker-compose up In terminal 2: # Start the external broker
docker-compose -p mosquitto -f docker-compose.mosquitto.yml up -d
Result: Both services start and hang at
|
ConnectRetry
and AutoReconnect
do not work when connecting to docker hostConnectRetry
and AutoReconnect
do not work when connecting to docker host on MacOS
Unfortunately I don't have access to a Mac so am going to struggle to debug this (as you mention it works OK under Windows/Linux). I suspect that the connection to the broker is being opened to a black hole (so the connection stays open but nothing is received). Can you please try https://github.com/ChIoT-Tech/paho.mqtt.golang/tree/Issue597 and see if that resolves the issue? If not some additional logging will be needed to identify what is happening. |
Hi @MattBrittan . Thank you for the swift response. Yes this does resolve the issue. I'll link to that for the time being and await the merge. |
Summary
When attempting to connect from a docker container to a broker running on the host, the client successfully connects as long as the broker is running. However:
ConnectRetry
set, the client will not connect if the broker starts after the clientAutoReconnect
set, the client will not reconnect if the broker stops then startsSteps to Reproduce/Minimum Working Example
In this fork I have adapted the
/cmd/docker
example to allow connection to a broker on the host machine, and documented changes and steps to reproduce in the example readme.I repeat these in the next comment (below).
System Info
OS: macOS Big Sur Version 11.6.5
Docker version 20.10.13, build a224086
I have separately tested on WSL/Ubuntu and the bug does not appear:
WSL Ubuntu 20.04
Docker version 20.10.14, build a224086
The text was updated successfully, but these errors were encountered: