Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit 15bf19a

Browse files
author
Aaron Meihm
authored
Merge pull request #10 from mozilla-services/exceptpanic
dont start serving requests until exceptions have been populated
2 parents 6f86ab3 + 10cda01 commit 15bf19a

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

exception.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
var activeTree *iptree.IPTree
1818
var treeLock sync.Mutex
19+
var isExceptionUpdate bool = false
1920

2021
type awsIPRanges struct {
2122
Prefixes []struct {
@@ -28,6 +29,14 @@ const awsIPRangeURL = "https://ip-ranges.amazonaws.com/ip-ranges.json"
2829
func startExceptions() {
2930
for {
3031
loadExceptions()
32+
33+
// If this was the first exception load, send a note to the main thread
34+
// to indicate the API can begin processing requests
35+
if !isExceptionUpdate {
36+
sruntime.exceptionsLoaded <- true
37+
isExceptionUpdate = true
38+
}
39+
3140
time.Sleep(time.Hour)
3241
}
3342
}
@@ -83,6 +92,7 @@ func loadExceptions() {
8392
treeLock.Lock()
8493
activeTree = t
8594
treeLock.Unlock()
95+
8696
log.Info("completed exception refresh")
8797
}
8898

iprepd.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
)
1212

1313
type serverRuntime struct {
14-
cfg serverCfg
15-
redis redisLink
16-
versionResponse []byte
14+
cfg serverCfg
15+
redis redisLink
16+
versionResponse []byte
17+
exceptionsLoaded chan bool
1718
}
1819

1920
type serverCfg struct {
@@ -91,6 +92,7 @@ func StartDaemon(confpath string) {
9192
log.Infof("starting daemon")
9293

9394
var err error
95+
sruntime.exceptionsLoaded = make(chan bool, 1)
9496
sruntime.cfg, err = loadCfg(confpath)
9597
if err != nil {
9698
log.Fatalf(err.Error())
@@ -104,6 +106,12 @@ func StartDaemon(confpath string) {
104106
log.Warnf(err.Error())
105107
}
106108
go startExceptions()
109+
select {
110+
case <-sruntime.exceptionsLoaded:
111+
log.Infof("initial exception load completed, starting API")
112+
case <-time.After(5 * time.Second):
113+
log.Fatalf("initial exception load timed out")
114+
}
107115
err = startAPI()
108116
if err != nil {
109117
log.Fatalf(err.Error())

0 commit comments

Comments
 (0)