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

Bridging to AWS IoT keeps failing with "Socket error on client local.xyz.awsiot, disconnecting." #1486

Open
mludvig opened this issue Nov 3, 2019 · 11 comments

Comments

@mludvig
Copy link

mludvig commented Nov 3, 2019

I'm trying to bridge a local broker to two remote brokers - one is Mosquitto based and the second one is AWS IoT. For some reason the connection to AWS IoT keeps closing all the time with Socket error on client local.xyz.awsiot, disconnecting.. The Mosquitto connection works well.

Here is my sample mosquitto.conf ...

### Bridge to test.mosquitto.org
connection test_mosquitto_org
address test.mosquitto.org

topic xyz/# out

bridge_protocol_version mqttv311

cleansession true
start_type automatic
notifications false
log_type all

### Bridge to AWS IOT
# AWS IoT endpoint, use AWS CLI 'aws iot describe-endpoint'
connection awsiot
address abcdefghjkl.iot.ap-southeast-2.amazonaws.com:8883

topic xyz/# both

bridge_protocol_version mqttv311
bridge_insecure false

cleansession true
start_type automatic
notifications false
log_type all

bridge_cafile   /etc/mosquitto/certs/rootCA.pem
bridge_certfile /etc/mosquitto/certs/cert.crt
bridge_keyfile  /etc/mosquitto/certs/private.key

When I start mosquitto with this config it seems to connect to both endpoints:

1572821579: mosquitto version 1.6.7 starting
1572821579: Config loaded from bridge.conf.
1572821579: Opening ipv4 listen socket on port 1883.
1572821579: Opening ipv6 listen socket on port 1883.
1572821579: Bridge local.xyz.test_mosquitto_org doing local SUBSCRIBE on topic xyz/#
1572821579: Connecting bridge (step 1) test_mosquitto_org (test.mosquitto.org:1883)
1572821579: Bridge local.xyz.awsiot doing local SUBSCRIBE on topic xyz/#
1572821579: Connecting bridge (step 1) awsiot (abcdefghjkl.iot.ap-southeast-2.amazonaws.com:8883)
1572821580: Connecting bridge (step 2) test_mosquitto_org (test.mosquitto.org:1883)
1572821580: Connecting bridge (step 2) awsiot (abcdefghjkl.iot.ap-southeast-2.amazonaws.com:8883)
1572821580: Bridge xyz.awsiot sending CONNECT
1572821580: Bridge xyz.test_mosquitto_org sending CONNECT
1572821581: Received CONNACK on connection local.xyz.test_mosquitto_org.
1572821581: Bridge local.xyz.test_mosquitto_org sending UNSUBSCRIBE (Mid: 1, Topic: xyz/#)
1572821581: Received CONNACK on connection local.xyz.awsiot.
1572821581: Bridge local.xyz.awsiot sending SUBSCRIBE (Mid: 1, Topic: xyz/#, QoS: 0, Options: 0x00)
1572821581: Received SUBACK from local.xyz.awsiot
1572821581: Received UNSUBACK from local.xyz.test_mosquitto_org

However as soon as I publish a message to the local broker the AWS IoT connection starts crashing:

1572821604: New connection from 127.0.0.1 on port 18833.
1572821604: New client connected from 127.0.0.1 as mosq-f2AcX35ovhb4OmJOhC (p2, c1, k60).
1572821604: No will message specified.
1572821604: Sending CONNACK to mosq-f2AcX35ovhb4OmJOhC (0, 0)
1572821604: Received PUBLISH from mosq-f2AcX35ovhb4OmJOhC (d0, q0, r1, m0, 'xyz/test', ... (73 bytes))
1572821604: Sending PUBLISH to local.xyz.test_mosquitto_org (d0, q0, r1, m0, 'xyz/test', ... (73 bytes))
1572821604: Sending PUBLISH to local.xyz.awsiot (d0, q0, r1, m0, 'xyz/test', ... (73 bytes))
1572821604: Received DISCONNECT from mosq-f2AcX35ovhb4OmJOhC
1572821604: Client mosq-f2AcX35ovhb4OmJOhC disconnected.
1572821604: Socket error on client local.xyz.awsiot, disconnecting.

1572821610: Bridge local.xyz.awsiot doing local SUBSCRIBE on topic xyz/#
1572821610: Connecting bridge (step 1) awsiot (abcdefghjkl.iot.ap-southeast-2.amazonaws.com:8883)
1572821610: Connecting bridge (step 2) awsiot (abcdefghjkl.iot.ap-southeast-2.amazonaws.com:8883)
1572821610: Bridge xyz.awsiot sending CONNECT
1572821610: Received CONNACK on connection local.xyz.awsiot.
1572821610: Bridge local.xyz.awsiot sending SUBSCRIBE (Mid: 2, Topic: xyz/#, QoS: 0, Options: 0x00)
1572821610: Sending PUBLISH to local.xyz.awsiot (d0, q0, r1, m0, 'xyz/test', ... (73 bytes))
1572821610: Received SUBACK from local.xyz.awsiot
1572821610: Socket error on client local.xyz.awsiot, disconnecting.
[... and so on, it keeps re-connecting and crashing ...]

I'm pretty sure it's not the AWS IoT configuration or the SSL certificates because with mosquitto_pub with the same certs I can submit messages to AWS IoT.

I'm using the latest mosquitto 1.6.7 on Linux Mint 19.1 and on Ubuntu 18.04, getting the same issue.

@karlp
Copy link
Contributor

karlp commented Nov 3, 2019

you look like you're missing "try_private false"

@mludvig
Copy link
Author

mludvig commented Nov 4, 2019

Thanks, just tried both try_private false and try_private true and it doesn't help. Still getting Socket error ...

@ckrey
Copy link

ckrey commented Nov 4, 2019

AWS does not support Retained messages but you are publishing a retained message:

1572821604: Received PUBLISH from mosq-f2AcX35ovhb4OmJOhC (d0, q0, r1, m0, 'xyz/test', ... (73 bytes))
1572821604: Sending PUBLISH to local.xyz.test_mosquitto_org (d0, q0, r1, m0, 'xyz/test', ... (73 bytes))
1572821604: Sending PUBLISH to local.xyz.awsiot (d0, q0, r1, m0, 'xyz/test', ... (73 bytes))

https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html

@ethsonliu
Copy link

ethsonliu commented Nov 7, 2019

This is same with Google IoT, see https://cloud.google.com/iot/docs/requirements#mqtt_bridge.

@mludvig
Copy link
Author

mludvig commented Nov 7, 2019

Thanks you’re right, publishing without retain flag works. Unfortunately we need the messages retained on the primary broker.

Is there any way to clear the flag before forwarding it to AWS or Google?

@ralight
Copy link
Contributor

ralight commented Nov 7, 2019

@mludvig Not in released versions, but this does what you need: 2af260b

@Kajvdh
Copy link

Kajvdh commented Oct 16, 2020

@ralight seems like this commit was never merged in the later versions after it. Do you know if there is at this time a workaround?

@AikHong
Copy link

AikHong commented Oct 16, 2020 via email

@jonahtomrobinson
Copy link

@ralight seems like this commit was never merged in the later versions after it. Do you know if there is at this time a workaround?

I'm also running into this issue. It would be really useful to have this forgotten feature integrated.

@meierthomas
Copy link

I just stumbled upon this as well. Given I'm not a developer and there's no released version of this means I'd have to go back to the actual devices to manage retain.

The option of turning this off completely or even by topic would be a great addition to the broker. However I'm not sure what's involved or whether there is demand for this.

@mludvig are you saying bridging your main broker to (remote) Mosquitto works even with messages containing retain=yes? If yes, my workaround may have to be to run an instance of Mosquitto on say AWS or check out the IBM Watson IoT service.

@pawel-smth
Copy link

As the topic is still open, posting for those who will be looking for similar info about "retain".

Changelog for v2.0.0 (https://mosquitto.org/ChangeLog.txt) mentions:
"- Add bridge_outgoing_retain option, to allow outgoing messages from a
bridge to have the retain bit completely disabled, which is useful when
bridging to e.g. Amazon or Google."

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

No branches or pull requests

10 participants