-
Notifications
You must be signed in to change notification settings - Fork 534
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
SetWriteTimeout doesn't work right? #436
Comments
Okay the problem seems to be the token.Wait(), which waits for a response by the broker. (this was my fault) [net] incoming stopped with error EOF
[net] error triggered, stopping
2020/06/30 14:58:37 Lost connection to MQTT Broker: EOF
[client] dial tcp ip:8883: i/o timeout
[client] dial tcp ip:8883: i/o timeout
2020/06/30 14:59:38 Sended
[client] dial tcp ip:8883: i/o timeout
[client] dial tcp ip:8883: i/o timeout
2020/06/30 15:00:44 Sended
[client] dial tcp ip:8883: i/o timeout It is caused by the Publish itself which needs some time if the connection isn't established. I dont know if that is caused by using a filestore, but why isn't the reconnect process asynchron like the sending process ? So if you want to wait for a reconnect you wait for the token (token.Wait()) ? |
Hi @Tockra, I did notice some issues with this when looking at the code last week (first time I needed to use a write timeout). The writetimeout is not applied to all writes (for instance in Connect or for 'Priority' messages). However I don't think that this is related to your issue. As you say your initial example is explained by the fact that
I'm not sure what you mean by this. If The above contains some guess as to why you may be seeing what you are. However as the library has a lot of options it's very hard to assist without a full logs from the library (enable DEBUG logging) and, ideally, a minimal reproducible example. Matt |
I mean that the Publish() function needs some time to return when the client isn't connected with the broker. I think it trys some reconnects or something else. But why isn't that asynchron? And what is the natural way to check if a message was transmitted or not (because of timeout to broker) ? WriteTimeout seems not to has a effect |
Apologies; I thought your comment was with regards to the reconnect process (which is async). As you point out
WriteTimeout does have an effect in that it sets a timeout on the Write that actually transmits the published message (as mentioned there are a few other writes that do not implement the timeout) and causes the Publish command to exit if messages are being queued up (a QOS 1+ message should still be delivered when the reconnection is complete). The issue is that at QOS 1+ writing the message to the network link does not complete the process (at higher QOS levels the message is only considered to have been delivered after a number of messages have been passed back and forth). If you are using QOS 0 then While it would be possible to change this to provide confidence that the message has been delivered I'm not sure how beneficial that would be. The reason I say this is that we can only check that the message has been delivered to the broker (and have no information about its delivery to the end consumer(s)). |
Okay, so it is intended that publish doesn't return instantly if there is no connection to the broker? Or is it a bug? |
Personally I'd call this a bug (because its inconsistent with the way the other calls that return Token's work). Note that in order to always return instantly we would need to use a buffered channel so there will always be a point at which the return is not instant. |
Yes of course. But that is clear. But the current behavior of Publish is a little bit strange ... |
Hi Guys,
I created a mqtt.Client with
SetWriteTimeout(time.Second * 10)
.But when I call
Then I blocked mqtt broker with iptables. After that Publish blocks and doesn't return.
But shouldn't it fails after 10 seconds?
T
The text was updated successfully, but these errors were encountered: