Skip to content

Commit

Permalink
Add TM poller panic stacktrace
Browse files Browse the repository at this point in the history
Currently, if the poller panics, it prints a useless error. This
changes it to print the stacktrace, making it possible to debug
the line and call stack of the nil pointer reference.
  • Loading branch information
rob05c authored and elsloo committed Feb 19, 2018
1 parent 5ec7187 commit 8227159
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions traffic_monitor/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"math/rand"
"net/http"
"os"
"runtime"
"sync/atomic"
"time"

Expand Down Expand Up @@ -135,6 +136,7 @@ func (p MonitorConfigPoller) Poll() {
} else {
log.Errorf("MonitorConfigPoller failed without panic\n")
}
log.Errorf("%s\n", stacktrace())
os.Exit(1) // The Monitor can't run without a MonitorConfigPoller
}()
for {
Expand Down Expand Up @@ -273,7 +275,7 @@ func diffConfigs(old HttpPollerConfig, new HttpPollerConfig) ([]string, []HTTPPo
Interval: new.Interval,
NoKeepAlive: new.NoKeepAlive,
ID: id,
PollConfig: pollCfg,
PollConfig: pollCfg,
})
}
return deletions, additions
Expand All @@ -289,7 +291,7 @@ func diffConfigs(old HttpPollerConfig, new HttpPollerConfig) ([]string, []HTTPPo
Interval: new.Interval,
NoKeepAlive: new.NoKeepAlive,
ID: id,
PollConfig: newPollCfg,
PollConfig: newPollCfg,
})
}
}
Expand All @@ -301,10 +303,22 @@ func diffConfigs(old HttpPollerConfig, new HttpPollerConfig) ([]string, []HTTPPo
Interval: new.Interval,
NoKeepAlive: new.NoKeepAlive,
ID: id,
PollConfig: newPollCfg,
PollConfig: newPollCfg,
})
}
}

return deletions, additions
}

func stacktrace() []byte {
initialBufSize := 1024
buf := make([]byte, initialBufSize)
for {
n := runtime.Stack(buf, true)
if n < len(buf) {
return buf[:n]
}
buf = make([]byte, len(buf)*2)
}
}

0 comments on commit 8227159

Please sign in to comment.