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

Hang on publish after unplug ethernet #313

Closed
Karl-Wu opened this issue May 3, 2019 · 2 comments
Closed

Hang on publish after unplug ethernet #313

Karl-Wu opened this issue May 3, 2019 · 2 comments

Comments

@Karl-Wu
Copy link

Karl-Wu commented May 3, 2019

With following topology, unplug the ethernet wire with X. Then my client program will hang on publish. It is kind of similar with #138 .
+--------+ +-----------+
|pahoo | +--------+ | |
|mqtt go +--------+Eth Switch+---------+ Broker |
+--------+ +--------+ X +-----------+

After some investigations, I found out that it is blocked on enquing buffered channel, which was full because of the network failure.
For now, my solution is drain out the buffered channel in (c *client) disconnect() and func (c *client) internalConnLost(err error). The drain out function is as following
func (c *client) drainOutChannels() {
//drain channels
for {
breakOut := false
select {
case pub := <-c.obound:
pub.t.setError(errors.New("Not Connected"))
case msg := <-c.oboundP:
msg.t.setError(errors.New("Not Connected"))
default:
breakOut = true
}
if breakOut {
break
}
}
}
Obviously, there should have a notification in the token to let user take of discarding messages.

The solution seems working for me, until I start a timer to keep try to connect. This time the cause is the client struct was not well protected. The timer, which call the connect and publish, the goroutine which take care of network error, will both write the client struct.

So my second solution is create a "disconnecting" state to prevent the caller access the client struct.

Thanks

@MattBrittan
Copy link
Contributor

This should have been addressed by pr #335 (it will return after 30s by default; alternatively set options.WriteTimeout).

@MattBrittan
Copy link
Contributor

Closing due to age/inactivity. Please feel free to reopen if this issue is occurring with the current release.

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

2 participants