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

Socket error on client, disconnecting. 1.4.8 on OSX. #7

Closed
ralight opened this issue Mar 15, 2016 · 20 comments
Closed

Socket error on client, disconnecting. 1.4.8 on OSX. #7

ralight opened this issue Mar 15, 2016 · 20 comments

Comments

@ralight
Copy link
Contributor

ralight commented Mar 15, 2016

migrated from Bugzilla #488633
status ASSIGNED severity normal in component Mosquitto for 1.4
Reported in version 1.4 on platform PC
Assigned to: Roger Light

On 2016-02-27 19:02:59 -0500, James Lewis wrote:

Here's the test conditions:

Localhost only.

Broker Process:
Run Mosquitto 1.4.8 in verbose mode
$ mosquitto -v

Subscriber Process:
Subscribe to localhost with a test topic "debug".
$ mosquitto_sub -h 127.0.0.1 -i testSub -t debug

Publisher Process:
Publish a message to localhost with the same test topic, "debug".
$ mosquitto_pub -h 127.0.0.1 -i testPublish -t debug -m 'Hello World'

The Broker process will report;
1456617536: New connection from 127.0.0.1 on port 1883.
1456617536: New client connected from 127.0.0.1 as testPublish (c1, k60).
1456617536: Socket error on client testPublish, disconnecting.

No errors are reported from the publish process:
1456617552: New connection from 127.0.0.1 on port 1883.
1456617552: New client connected from 127.0.0.1 as testSub (c1, k60).

On my Mac I will still see the message on the Publisher process. However, I have heard from others that they have intermittent success. Even if I use 1.4.7 or 1.4.5 versions of mosquitto_pub and mosquitto_sub the Broker process will always report a "Socket error on client."

If I change ONLY the broker to 1.4.5, the error never occurs. On the machine that has intermittent success, running 1.4.5 ss the broker (simply replacing only the mosquitto binary) results in expected functioning.

Verified firewall set to "allow incoming connections."

On 2016-03-07 17:28:25 -0500, Roger Light wrote:

Thanks for this, I've found the problem which comes from a Windows related change. I've got a fix for OSX, but need to check there are no regressions on Windows.

@robfrei
Copy link

robfrei commented Jun 12, 2016

I am, unfortunately, experiencing this same problem. I've installed Mosquitto on my Mac using Home-brew (version 1.4.8). Any update on the fix? Thanks.

@silentred
Copy link

same problem here. 1.4.8 installed from home-brew

@ralight ralight added this to the Fixes-next milestone Jun 13, 2016
@ralight
Copy link
Contributor Author

ralight commented Jun 13, 2016

I apologise, this fell through the cracks for 1.4.9. I've pushed a fix that will be in the next release.

@ralight ralight closed this as completed Jun 13, 2016
@leesohaeng
Copy link

I got a same problem version 1.4.9 on OS X.
I hope this problem fix next release.


LEE-SOHAENGui-MacBook-Pro:~ sohaenglee$ /usr/local/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf
1470667050: mosquitto version 1.4.9 (build date 2016-06-18 16:16:49+0100) starting
1470667050: Config loaded from /usr/local/etc/mosquitto/mosquitto.conf.
1470667050: Opening ipv4 listen socket on port 1883.
1470667050: Opening ipv6 listen socket on port 1883.
1470667051: New connection from 127.0.0.1 on port 1883.
1470667051: New client connected from 127.0.0.1 as mosqsub/15501-LEE-SOHAE (c1, k60).
1470667051: New connection from 127.0.0.1 on port 1883.
1470667051: New client connected from 127.0.0.1 as mqttjs_fbda98eb (c1, k10).
1470667062: New connection from 127.0.0.1 on port 1883.
1470667062: New client connected from 127.0.0.1 as mosqpub/15707-LEE-SOHAE (c1, k60).
1470667062: Socket error on client mosqpub/15707-LEE-SOHAE, disconnecting.
1470667330: Socket error on client mosqsub/15501-LEE-SOHAE, disconnecting.
1470667351: New connection from ::1 on port 1883.
1470667351: New client connected from ::1 as mosqsub/16056-LEE-SOHAE (c1, k60).
1470667394: New connection from ::1 on port 1883.
1470667394: New client connected from ::1 as mosqpub/16137-LEE-SOHAE (c1, k60).
1470667394: Socket error on client mosqpub/16137-LEE-SOHAE, disconnecting.
1470667683: New connection from 10.0.1.3 on port 1883.
1470667683: New client connected from 10.0.1.3 as testClient (c1, k30).
1470667737: Socket error on client testClient, disconnecting.
1470667741: Socket error on client mosqsub/16056-LEE-SOHAE, disconnecting.
1470667774: New connection from 127.0.0.1 on port 1883.
1470667774: New client connected from 127.0.0.1 as mosqsub/16495-LEE-SOHAE (c1, k60).
1470667779: New connection from ::1 on port 1883.
1470667779: New client connected from ::1 as mosqpub/16500-LEE-SOHAE (c1, k60).
1470667779: Socket error on client mosqpub/16500-LEE-SOHAE, disconnecting.
1470667780: New connection from ::1 on port 1883.
1470667780: New client connected from ::1 as mosqpub/16510-LEE-SOHAE (c1, k60).
1470667780: Socket error on client mosqpub/16510-LEE-SOHAE, disconnecting.
1470667782: New connection from ::1 on port 1883.
1470667782: New client connected from ::1 as mosqpub/16520-LEE-SOHAE (c1, k60).

1470667782: Socket error on client mosqpub/16520-LEE-SOHAE, disconnecting.

sub : mosquitto_sub -h 127.0.0.1 -t topic/state
pub : mosquitto_pub -h 127.0.0.1 -t topic/state -m "testtest"

@ralight
Copy link
Contributor Author

ralight commented Aug 8, 2016

This is fixed in the fixes branch and will be released as part of 1.4.10.

@leesohaeng
Copy link

very thanks ralight~

@danobot
Copy link

danobot commented Mar 1, 2017

I am running 1.4.11 and I am still experiencing this problem.
Using Paho pYthon library to connect to broker. Another application connects to the same broke just fine using the same credentials.

# Program that listens for SET messages and replies with a status messages indicated that the action was successful.
SET_TOPIC = '/test_switch/set'
STATUS_TOPIC = '/test_switch'

import paho.mqtt.publish as mqtt
import paho.mqtt.client as mqtt_client


# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("$SYS/#")

# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    # print(msg.topic)
    if SET_TOPIC == msg.topic:
        print(msg.topic + " " + str(msg.payload))
        mqtt.single(STATUS_TOPIC, "ON")

client = mqtt_client.Client()
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set('hassbian', '3435')
client.connect("192.168.178.58", 1883)
client.subscribe(SET_TOPIC, 1)
# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
client.loop_forever()

@flexiti
Copy link

flexiti commented Mar 1, 2017

after last system update my mosquitto also stopped working via WebSocket
(Ubuntu 14.04)
I just commented

protocol websockets

now working mqtt protocol only
otherwise mosquitto not start at all

@ralight
Copy link
Contributor Author

ralight commented Mar 1, 2017

@flexiti Could you please open a separate issue? This one is not about websockets nor ubuntu.

@ralight
Copy link
Contributor Author

ralight commented Mar 1, 2017

@danobot The original issue is "running the broker on a mac, any client will have problems connecting". If you're saying it is only the python client that has problems it doesn't sound quite the same. The Python code does look ok though.

@flexiti
Copy link

flexiti commented Mar 1, 2017

@ralight
sorry, wrong window by mistake :)

@MahlerFive
Copy link

I'm experiencing the same issue intermittently.
Mac OS X
mosquitto 1.4.10

To reproduce I ran a broker:
$ mosquitto -v

I started a subscriber:
$ mosquitto_sub -t testtopic

I published several times:

$ mosquitto_pub -t testtopic -m "test message"
$ mosquitto_pub -t testtopic -m "test message"
$ mosquitto_pub -t testtopic -m "test message"
$ mosquitto_pub -t testtopic -m "test message"
$ mosquitto_pub -t testtopic -m "test message"
$ mosquitto_pub -t testtopic -m "test message"

The first 5 publishes were fine. They looked like this on the broker:

1489420020: New connection from 127.0.0.1 on port 1883.
1489420020: New client connected from 127.0.0.1 as mosqpub/75836-Jeffs-Mac (c1, k60).
1489420020: Sending CONNACK to mosqpub/75836-Jeffs-Mac (0, 0)
1489420020: Received PUBLISH from mosqpub/75836-Jeffs-Mac (d0, q0, r0, m0, 'testtopic', ... (12 bytes))
1489420020: Sending PUBLISH to mosqsub/75835-Jeffs-Mac (d0, q0, r0, m0, 'testtopic', ... (12 bytes))
1489420020: Received DISCONNECT from mosqpub/75836-Jeffs-Mac
1489420020: Client mosqpub/75836-Jeffs-Mac disconnected.

The last publish looked like this (note the socket error):

1489420043: New connection from 127.0.0.1 on port 1883.
1489420043: New client connected from 127.0.0.1 as mosqpub/75921-Jeffs-Mac (c1, k60).
1489420043: Sending CONNACK to mosqpub/75921-Jeffs-Mac (0, 0)
1489420043: Received PUBLISH from mosqpub/75921-Jeffs-Mac (d0, q0, r0, m0, 'testtopic', ... (12 bytes))
1489420043: Socket error on client mosqpub/75921-Jeffs-Mac, disconnecting.
1489420043: Sending PUBLISH to mosqsub/75835-Jeffs-Mac (d0, q0, r0, m0, 'testtopic', ... (12 bytes))

@mkeyno
Copy link

mkeyno commented Apr 8, 2017

I have same problem , I've installed last version of mosquitto on my raspberry pi Jessi , I have no problem to pub/sub either through terminal in raspberry pi or MQTT.fx 1.3.1 on my windows but when I use following paho mqtt client js it throw disconnected error , I might add I disable mod_websocket_mosquitto module on Apache server to prevent other websocket port conflict, however problem not resolved
error

1491637310: New connection from 192.168.1.101 on port 1883.
1491637310: Socket error on client <unknown>, disconnecting.

html page

<html xmlns="http:https://www.w3.org/1999/xhtml">
<head>
  <script type="text/javascript" src="mqttws31.js"></script>

  <script type="text/javascript">
  
  var client;
  var form = document.getElementById("tutorial");
  var  host =location.hostname;

  function doConnect() {
      client = new Paho.MQTT.Client(host, 1883, "ClientId");
      client.onConnect = onConnect;
      client.onMessageArrived = onMessageArrived;
      client.onConnectionLost = onConnectionLost;
      client.connect({onSuccess:onConnect});
  }
  
  function doSubscribe() {
      client.subscribe("/World");
  }
  
  function doSend() {
      message = new Paho.MQTT.Message("Hello");
      message.destinationName = "/World";
      client.send(message);
  }

  function doDisconnect() {
      client.disconnect();
  }
  
  // Web Messaging API callbacks
  
  function onConnect() {
      var form = document.getElementById("example");
      form.connected.checked= true;
  }
  
  function onConnectionLost(responseObject) {
      var form = document.getElementById("example");
      form.connected.checked= false;
      if (responseObject.errorCode !== 0)
          alert(client.clientId+"\n"+responseObject.errorCode);
  }
  
  function onMessageArrived(message) {
      var form = document.getElementById("example");
      form.receiveMsg.value = message.payloadString;
  }
  
  </script>
</head> 

<body>
  <h1>Example Web Messaging web page.</h1>
  <form id="example">
  <fieldset>
  <legend id="Connect" > Connect </legend>
    Make a connection to the server, and set up a call back used if a 
    message arrives for this client.
    <br>
    <input type="button" value="Connect" onClick="doConnect(this.form)" name="Connect"/>
    <input type="checkbox" name="connected" disabled="disabled"/>
  </fieldset>
  
  <fieldset>
  <legend id="Subscribe" > Subscribe </legend>
  Make a subscription to topic "/World".
  <br> <input type="button" value="Subscribe" onClick="doSubscribe(this.form)"/>
  </fieldset>
  
  <fieldset>
  <legend id="Send" > Send </legend>
    Create a Message object containing the word "Hello" and then publish it at
    the server.
    <br>
    <input type="button" value="Send" onClick="doSend(this.form)"/>
  </fieldset>
  
  <fieldset>
  <legend id="Receive" > Receive </legend>
    A copy of the published Message is received in the callback we created earlier.
  <textarea name="receiveMsg" rows="1" cols="40" disabled="disabled"></textarea>
  </fieldset>
  
  <fieldset>
  <legend id="Disconnect" > Disconnect </legend>
    Now disconnect this client from the server.
  <br> <input type="button" value="Disconnect" onClick="doDisconnect()"/>
  </fieldset>
  </form>
<!-- /body>
</html>

@samuel235
Copy link

I seem to be getting this "Socket error on client" issue on version 1.4.8-1build1. Will attempt to update further but would appreciate some sort of pointer in the right direction if anyone has any ideas.

@mkeyno
Copy link

mkeyno commented Apr 30, 2017

@samuel235 I've already use last 1.4.11 version

@Gyanender888
Copy link

i have faced the same issue ,doesn't occure with qos set to 0 ,Only happens when qos is 2

@lazy-coder-1
Copy link

how to connect clients (publisher & subscriber ) on mqtt mosquitto

edgd1er added a commit to edgd1er/Abeille that referenced this issue Feb 4, 2018
debug level is extracted from jeedom

Added Qos parameters for daemons (not working on docker due to a bug (clients disconnection: might be related to eclipse/mosquitto#7)
@cwalther
Copy link

cwalther commented Nov 4, 2018

This problem is still present in 1.5.3, 23113bb does not fix it for unencrypted connections. Reproduced in the same way as described in the original post.

When a client sends a PUBLISH, then a DISCONNECT, then closes the connection in quick enough succession that the three events arrive in the same poll notification on the server, the server will process the PUBLISH, then notice the disconnection and treat it as an abnormal one, and ignore the DISCONNECT. That appears to be because (near the end of loop.c) SSL_DATA_PENDING(context) is always false due to context->ssl == null and therefore only one packet is processed before the pollfds[context->pollfd_index].revents are looked at and the POLLHUP is detected.

@cwalther
Copy link

cwalther commented Nov 4, 2018

A simple fix seems to be

diff --git a/src/loop.c b/src/loop.c
index 9714720..44c37c5 100644
--- a/src/loop.c
+++ b/src/loop.c
@@ -812,6 +812,7 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol
 				}
 			}while(SSL_DATA_PENDING(context));
 		}
+		else
 #ifdef WITH_EPOLL
 		if(events & (EPOLLERR | EPOLLHUP)){
 #else

but I have not checked if it is correct in all cases.

@ralight
Copy link
Contributor Author

ralight commented Nov 4, 2018

That looks like a good way of addressing the problem, thanks for the suggestion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests