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

Broker sometimes kills connection to client #419

Closed
MahlerFive opened this issue Apr 6, 2017 · 4 comments
Closed

Broker sometimes kills connection to client #419

MahlerFive opened this issue Apr 6, 2017 · 4 comments

Comments

@MahlerFive
Copy link

Using mosquitto 1.4.10.

I have a client that publishes multiple messages to the same topic in batches (eg. 50 messages per batch). The client will send each batch every few seconds (eg. every 5 seconds). After 1 or a few batches are sent, on the next batch, suddenly mosquitto will kill the connection to the client.

I've provided a packet capture from the machine the broker is running on that shows the behaviour which I'll describe below.

mqtt_filtered.pcap.zip

Client: 172.16.0.114
Mosquitto Broker: 10.16.208.139 (port 8883)

The numbers below are the packet numbers in the capture file.

1: Client connects to broker
17?: Client starts publishing first batch of messages
386: First batch of messages complete
387: Client starts publishing second batch of messages
388: Missing packet?
389: Mosquitto ACKs packet 387
390: Mosquitto starts spamming TCP DUP ACK packets for 387
549: Mosquitto stops spamming TCP DUP ACK packets for 387
550-578: Lots of retransmissions
784: Second batch of messages complete
785: Third batch of messages starts
788: Mosquitto sends FIN ACK, closing the connection (WHY?)
790-880: Mosquitto responds to remaining messages with RST

The main question is why would mosquitto suddenly close the connection after starting to receiving the 3rd batch of messages. The logs in mosquitto at this point where the 3rd batch starts is here:

18:52:24
1491418344: OpenSSL Error: error:140E0197:SSL routines:SSL_shutdown:shutdown while in init
18:52:24
1491418344: Socket error on client admin, disconnecting.

@ralight
Copy link
Contributor

ralight commented Apr 7, 2017

Is this repeatable (looks like it if you have the pcap!) and can you provide some way I could try to reproduce it myself? Ideally a script or some code to run rather than a description, then I know I'm doing exactly the same thing.

@MahlerFive
Copy link
Author

It is consistently repeatable, however I can only seem to reproduce this in a production environment in AWS right now. I've tried to reproduce locally with no luck. I have ruled out the cause as being related to the AWS load balancer by bypassing it completely, and I've ruled out the cause as being related to the docker container it's running in, since I've run the same container locally without reproducing the issue.

Since the error seems related to SSL, I should mention that my config is probably a little unorthodox in that it supports both username/password login over TLS, as well as TLS-PSK logins. I've attached the config file here. The user getting disconnected in the above scenario authenticated with username/password, although there seem to be the same issues with TLS-PSK clients as well.

mosquitto.conf.zip

@MahlerFive
Copy link
Author

@ralight I think I found what is causing the problem. The AWS load balancer does a TCP health check every minute or so. This basically just sends a tcp packet to mosquitto. Naturally, this will cause an error for that connection in mosquitto since it's not using SSL. However, mosquitto not only kills the connection from the load balancer health check, it also kills my other connection! This explains the strange openssl error "shutdown while in init" which made no sense since the connection was already initialized.

I don't have a simple script to reproduce but here was my setup:

  • local docker container running mosquitto
  • one client connected via TLS (using username/password)
  • client periodically sends messages
  • send a tcp packet with content 0x01 to mosquitto
  • mosquitto kills both connections

je-ik pushed a commit to je-ik/mosquitto that referenced this issue May 30, 2017
je-ik pushed a commit to je-ik/mosquitto that referenced this issue May 30, 2017
je-ik pushed a commit to je-ik/mosquitto that referenced this issue May 30, 2017
je-ik added a commit to je-ik/mosquitto that referenced this issue May 31, 2017
ralight pushed a commit that referenced this issue Jun 11, 2017
@ralight
Copy link
Contributor

ralight commented Jul 18, 2017

This was fixed based on the pull request, thanks for your help.

@ralight ralight closed this as completed Jul 18, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants