Skip to content

Commit d95d2fd

Browse files
committedAug 4, 2017
fix segfault
ref #23 we were closing sockets that might not actually be open.
1 parent 7b859f9 commit d95d2fd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

Diff for: ‎main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package main
33
import (
44
"flag"
55

6+
"fmt"
67
"log"
78
"math/rand"
89
"net"
910
"os"
1011
"os/signal"
1112
"syscall"
1213
"time"
13-
"fmt"
1414
)
1515

1616
// config vars, to be manipulated via command line flags
@@ -57,8 +57,10 @@ func (a *Agent) flush() error {
5757

5858
if !cacheConns {
5959
defer func() {
60-
a.Connection.Close()
61-
a.Connection = nil
60+
if a.Connection != nil {
61+
a.Connection.Close()
62+
a.Connection = nil
63+
}
6264
}()
6365
}
6466

@@ -133,7 +135,7 @@ func main() {
133135

134136
if jitter.Nanoseconds() != 0 {
135137
// rand(jitter * 2) - jitter gives random +/- jitter values
136-
jitterDelay = time.Duration(rand.Int63n(jitter.Nanoseconds() * 2) - jitter.Nanoseconds())
138+
jitterDelay = time.Duration(rand.Int63n(jitter.Nanoseconds()*2) - jitter.Nanoseconds())
137139
}
138140
nextLaunch += jitterDelay
139141

0 commit comments

Comments
 (0)