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

Bug: MQTT client can receive the broker message but cannot send its own message to broker #1189

Closed
xiaofyao opened this issue Mar 6, 2019 · 7 comments
Labels
Status: Blocked Another issue needs to be resolved first

Comments

@xiaofyao
Copy link

xiaofyao commented Mar 6, 2019

Problem description:

MQTT client can receive the heartbeat from broker but cannot send its own message to broker

Influence:

Because MQTT client can receive heartbeat from broker, the client does not consider itself disconnected from the broker. So the client does not attempt to reconnect to the broker, broker will never receive any message from client.

suggestion:

I found that mosquitto use different socket for receiving and sending, that is why this problem arises.

@ralight
Copy link
Contributor

ralight commented Mar 6, 2019

Sorry, you're going to have to provide some more details here. Which client are you using? Do you consider there is a problem with the client or the broker? Mosquitto only uses a single socket per client, your last statement is incorrect.

@ralight ralight added the Status: Blocked Another issue needs to be resolved first label Mar 6, 2019
@xiaofyao
Copy link
Author

xiaofyao commented Mar 7, 2019

@ralight Thanks for your reply.

Detail of problem

  • I use the Aliyun broker. The client network environment is very unstable and client has two network cards.
  • This problem occurs when the client is disconnected from broker and reconnected about 30 times.
  • In an unstable network environment, if the client disconnects and reconnects to broker several times, the client will not be able to send message but can receive message from broker. At this time, the client will never disconnect the reconnect broker.

Source code

You can find that the mosquitto use different socket for receiving and sending.
If I understand wrong, please correct me.

type define:

mosq_sock_t sockpairR, sockpairW;

Create two sockets when connecting to the broker:
if(net__socketpair(&mosq->sockpairR, &mosq->sockpairW)){

Question

If the client receives the broker's heartbeat, it will assume that it is not disconnected from the broker?
I think the client should subscribe the heartbeat it sends to the broker so that it can loop back and check the connection status

@xiaofyao
Copy link
Author

xiaofyao commented Mar 8, 2019

@ralight @jacmet @xrmx @onip

Respected developers, could you please give me some guidance? If you need any further information, please let me know. Let's work together to improve this feature.

@ptjm
Copy link

ptjm commented Mar 8, 2019

The socketpair you're talking about above is used as a control mechanism. libmosquitto's i/o thread spends most of its time blocked on a select(). When some other thread wants the select to end, the other thread writes a byte to mosq->sockpairW. This makes mosq->sockpairR readable, and so the select() returns. Note that this code is used in the mosquitto client library, but not in mosquitto itself.

A single socket is used to communicate with the client. (mosq->sock). I guess if the client can receive a message from the broker, that socket must be valid. You might want to look at what's actually going on on the network using tcpdump or wireshark, or something in between.

@xiaofyao
Copy link
Author

xiaofyao commented Mar 8, 2019

@ptjm Thanks you for your reply.
In order to check the connection state more accurately, I think the client should subscribe the heartbeat it sends to the broker so that it can loop back and check the connection status.
Now my guess is that as long as the client can receive the message from broker, the client won't think the connection is broken.
If I understand wrong, please correct me.

Best Regards,
xiaofyao

@ralight
Copy link
Contributor

ralight commented Mar 8, 2019

Could you provide some example code that demonstrates the problem?

The pingreq/pingresp heartbeat is handled by the client library as long as you are correctly using one of the mosquitto_*loop*() functions, and it isn't possible to be unsubscribed from those messages.

If you mean a different heartbeat, then it is an application level heartbeat that is not part of libmosquitto.

@ralight
Copy link
Contributor

ralight commented Apr 11, 2019

I'm closing this because as it stands I can't do anything about it, and don't believe the problem is in this project. If you still have a problem, please reopen and provide more information.

@ralight ralight closed this as completed Apr 11, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Aug 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Status: Blocked Another issue needs to be resolved first
Projects
None yet
Development

No branches or pull requests

3 participants