Skip to content
Snippets Groups Projects
Commit d4ddb5cf authored by Josh Brooks's avatar Josh Brooks
Browse files

Add prose worthy comments explaining the bug fix

parent 1e39f030
No related branches found
No related tags found
2 merge requests!510Release,!398Add debug log for file transfer not quitting
...@@ -74,32 +74,44 @@ func (m *manager) sendingThread(stop *stoppable.Single) { ...@@ -74,32 +74,44 @@ func (m *manager) sendingThread(stop *stoppable.Single) {
healthChanID := m.cmix.AddHealthCallback(func(b bool) { healthChan <- b }) healthChanID := m.cmix.AddHealthCallback(func(b bool) { healthChan <- b })
for { for {
select { select {
// A quit signal has been sent by the user. Typically, this is a result
// of a user-level shutdown of the client.
case <-stop.Quit(): case <-stop.Quit():
jww.DEBUG.Printf("[FT] Stopping file part sending thread (%s): "+ jww.DEBUG.Printf("[FT] Stopping file part sending thread (%s): "+
"stoppable triggered.", stop.Name()) "stoppable triggered.", stop.Name())
m.cmix.RemoveHealthCallback(healthChanID) m.cmix.RemoveHealthCallback(healthChanID)
stop.ToStopped() stop.ToStopped()
return return
// If the network becomes unhealthy, we will cease sending files until
// it is resolved.
case healthy := <-healthChan: case healthy := <-healthChan:
// There exists an edge case where an unhealthy signal is received
// due to a user-level shutdown, meaning the health tracker has
// ceased operation. If the health tracker is shutdown, a healthy
// signal will never be received, and this for loop will run
// infinitely. If we are caught in this loop, the stop's Quit()
// signal will never be received in case statement above, and this
// sender thread will run indefinitely. To avoid lingering threads
// in the case of a shutdown, we must actively listen for either the
// Quit() signal or a network health update here.
for !healthy { for !healthy {
select { select {
case <-stop.Quit(): case <-stop.Quit():
// It's possible during shutdown that the health tracker gets // Listen for a quit signal if the network becomes unhealthy
// shutdown before the quit signal is received by the case // before a user-level shutdown.
// statement listening for stop.Quit() above. As a result, we
// must listen for the quit signal here, to avoid waiting
// for a healthy signal that will never come.
jww.DEBUG.Printf("[FT] Stopping file part sending "+ jww.DEBUG.Printf("[FT] Stopping file part sending "+
"thread (%s): stoppable triggered.", stop.Name()) "thread (%s): stoppable triggered.", stop.Name())
m.cmix.RemoveHealthCallback(healthChanID) m.cmix.RemoveHealthCallback(healthChanID)
stop.ToStopped() stop.ToStopped()
return return
// If a quit signal is not received, we must wait until the // Wait for a healthy signal before continuing to send files.
// network is healthy before we can continue sending files.
case healthy = <-healthChan: case healthy = <-healthChan:
} }
} }
// A file part has been sent through the queue and must be sent by
// this thread.
case packet := <-m.sendQueue: case packet := <-m.sendQueue:
m.sendCmix(packet) m.sendCmix(packet)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment