Skip to content

Commit

Permalink
fix hang on i/o timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
braye committed Feb 19, 2022
1 parent a1627b4 commit 8ac4309
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ The tool has a simple client-server architecture. Run `bounceback` on the endpoi

Next, launch the client on the endpoint you wish to measure latency from, passing the hostname of the server with the `--host` argument. The client will begin passing packets to the server, and measuring the round-trip-time. It will report any significant excursions from mean, defined as 10x the rolling average of the last 256 packets. These outliers are automatically removed from the rolling average.

There is throttling in place, such that the client will never send more than 60 packets/sec. This can be overriden with the `--rate` flag, which specifies the number of packets/second to send.

**Warning:** The client currently doesn't recover from packet loss gracefully. This will be of limited use, it its current form, for troubleshooting dropped packets.
There is throttling in place, such that the client will never send more than 60 packets/sec. This can be overriden with the `--rate` flag, which specifies the number of packets/second to send.
14 changes: 10 additions & 4 deletions bounceback.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func main() {
fmt.Println("bounceback 0.2.0")
fmt.Println("bounceback 0.2.1")

mode := "server"
port := 31337
Expand Down Expand Up @@ -118,16 +118,20 @@ func bouncebackClient(host string, port int, rate int) {
log.Fatal(err)
}

timeout, _ := time.ParseDuration("1000ms")

log.Printf("Connected to %s, gathering baseline...", destAddr)

// int64s because why not
var seq uint64
pktHistory := make([]int64, 256)
var rollingAverage int64

// main packet sending loop
for {
nextPktTime := time.Now().Add(throttlePosition)
timeoutTime := time.Now().Add(timeout)
conn.SetReadDeadline(timeoutTime)
seq++
msg := make([]byte, 8)
resp := make([]byte, 8)
Expand All @@ -147,8 +151,10 @@ func bouncebackClient(host string, port int, rate int) {
rtt := time.Since(sentTime)
rttMicroseconds := int64(rtt.Microseconds())
if err != nil {
log.Println("Error reading UDP response")
log.Fatal(err)
log.Println(err)
log.Println("Error reading UDP packet, sleeping 5 seconds and retrying.")
time.Sleep(5 * time.Second)
continue
}

respInt := binary.LittleEndian.Uint64(resp)
Expand Down

0 comments on commit 8ac4309

Please sign in to comment.