You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
The text was updated successfully, but these errors were encountered: