@@ -39,14 +39,15 @@ const (
3939 prequelRulesSha256Suffix = ".sha2"
4040 prequelRulesSigSuffix = ".sig"
4141 tmpDirPrefix = "preq-update"
42- defaultLocalCheckDur = 24 * time .Hour * 2 // 2 days
42+ defaultLocalCheckDur = 24 * time .Hour * 1 // 1 day
4343)
4444
4545const (
4646 retries = uint (1 )
4747 rulesFilenameFmt = prefix .PrequelPublicRulesPrefix + "%s" + prequelRulesSuffix
48- fastCheckTimeout = 100 * time .Millisecond
48+ fastCheckTimeout = 150 * time .Millisecond
4949 slowCheckTimeout = 300 * time .Millisecond
50+ noRulesTimeout = 5 * time .Second
5051 downloadTimeout = 30 * time .Second
5152)
5253
@@ -145,6 +146,7 @@ func syncUpdates(ctx context.Context, conf *config.Config, configDir, token, upd
145146 currRulesPath string
146147 apiUrl = fmt .Sprintf ("https://%s:%d" , baseAddr , tlsPort )
147148 dur = defaultLocalCheckDur
149+ timeout = slowCheckTimeout
148150 err error
149151 )
150152
@@ -164,14 +166,23 @@ func syncUpdates(ctx context.Context, conf *config.Config, configDir, token, upd
164166 return currRulesPath , err
165167 }
166168
169+ // If we don't have any rules installed, then bump the timeout and force a full checkin
170+ if currRulesPath == "" {
171+ timeout = noRulesTimeout
172+ localCheckUpdate = true
173+ log .Warn ().
174+ Str ("timeout" , timeout .String ()).
175+ Msg ("No rules installed yet. Increasing timeout and forcing a full checkin" )
176+ }
177+
167178 // If we don't need to do a full check in, do a fast one (~30ms)
168179 if ! localCheckUpdate {
169180 if tinyResp , err = fastUpdateSync (ctx , fmt .Sprintf ("%s:%d" , udpBaseAddr , udpPort ), fastCheckTimeout ); err != nil {
170181 return currRulesPath , err
171182 }
172183 } else {
173184 // Otherwise, do a full check in (~130ms). Uses slowCheckTimeout
174- if fullResp , err = checkin (ctx , apiUrl , token , currRulesVer , slowCheckTimeout ); err != nil {
185+ if fullResp , err = checkin (ctx , apiUrl , token , currRulesVer , timeout ); err != nil {
175186 return currRulesPath , err
176187 }
177188 }
@@ -181,7 +192,7 @@ func syncUpdates(ctx context.Context, conf *config.Config, configDir, token, upd
181192 // Ok, we need to do one or more updates. But we don't know if we have a full response.
182193 if fullResp == nil {
183194 // Otherwise, do a full check in (~130ms). Uses slowCheckTimeout
184- if fullResp , err = checkin (ctx , apiUrl , token , currRulesVer , slowCheckTimeout ); err != nil {
195+ if fullResp , err = checkin (ctx , apiUrl , token , currRulesVer , timeout ); err != nil {
185196 return currRulesPath , err
186197 }
187198 }
0 commit comments