summaryrefslogtreecommitdiffhomepage
path: root/send.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2018-04-18 20:29:48 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2018-04-18 20:29:48 +0200
commitac9912345b4da5034ea93f5f245ea2ce04815bd5 (patch)
treeb371c03e54c7d1ee2c882fdf596b011a936d2ad7 /send.go
parent26a56a652eeeece7677ba4f1896da34c83930652 (diff)
Fixed read from closed channel
A premature waitgroup .Done resulted in reading from closed channel. This caused a nil-pointer deref & crash. Added additional debugging when closing routines.
Diffstat (limited to 'send.go')
-rw-r--r--send.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/send.go b/send.go
index 5a59f6e..df8efdb 100644
--- a/send.go
+++ b/send.go
@@ -320,13 +320,16 @@ func (device *Device) RoutineEncryption() {
*/
func (peer *Peer) RoutineSequentialSender() {
- defer peer.routines.stopping.Done()
-
device := peer.device
logDebug := device.log.Debug
logDebug.Println("Routine, sequential sender, started for", peer.String())
+ defer func() {
+ peer.routines.stopping.Done()
+ logDebug.Println(peer.String(), ": Routine, Sequential sender, Stopped")
+ }()
+
peer.routines.starting.Done()
for {
@@ -337,7 +340,12 @@ func (peer *Peer) RoutineSequentialSender() {
"Routine, sequential sender, stopped for", peer.String())
return
- case elem := <-peer.queue.outbound:
+ case elem, ok := <-peer.queue.outbound:
+
+ if !ok {
+ return
+ }
+
elem.mutex.Lock()
if elem.IsDropped() {
continue