geojs: a visitor's wait no longer cuts off the request to GeoJS (closes #404)
check / check (push) Failing after 2m16s
check / check (push) Failing after 2m16s
The GeoJS lookup and its cache move from internal/lookup to internal/geojs, which imports no other package of this repository. waf hands it functions to count requests, report failures and count lookups that went without an answer; waf keeps the log line, the source_failure alert and the metrics. The caller now passes its wait to each lookup. waf passes SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS. A request to GeoJS has its own fixed limit of 10 seconds, and only passing it or an error from GeoJS is a failure. An answer that comes after the caller stopped waiting is kept. internal/lookup keeps the lookup database and returns geojs.Answer. Model: opus-5-5
This commit was merged in pull request #407.
This commit is contained in:
1 parent
a2fcc00ded
commit
caa3079847
21 files changed
+645
-484
No files matched your search
@@ -12,7 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"sneak.berlin/go/smallwebwaf/internal/alerts"
|
||||
"sneak.berlin/go/smallwebwaf/internal/lookup"
|
||||
"sneak.berlin/go/smallwebwaf/internal/geojs"
|
||||
"sneak.berlin/go/smallwebwaf/internal/lookup/lookuptest"
|
||||
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
||||
)
|
||||
@@ -138,7 +138,7 @@ func TestRequestThatWaitedForItsLookupIsCountedWhenItGoesOn(t *testing.T) {
|
||||
// of lookups.json would keep it, while the first request still waits
|
||||
// for GeoJS. The second request goes on at once, and is counted.
|
||||
clk.advance(2500 * time.Millisecond)
|
||||
server.GeoJS.Load([]lookup.Answer{{
|
||||
server.GeoJS.Load([]geojs.Answer{{
|
||||
Client: netip.MustParsePrefix(
|
||||
fromDE + "/32",
|
||||
), ASN: asnDE, ASName: asNameDE,
|
||||
@@ -199,7 +199,7 @@ func TestASNumberAndNameInTheLogLineTheHistoryTheBanNotesAndTheAlert(
|
||||
// The answer is kept before the requests, so GeoJS is not asked, and
|
||||
// gives no answer of its own.
|
||||
netblock := netip.MustParsePrefix(fromDE + "/32")
|
||||
server.GeoJS.Load([]lookup.Answer{{
|
||||
server.GeoJS.Load([]geojs.Answer{{
|
||||
Client: netblock, ASN: asnDE, ASName: asNameDE, Country: "DE",
|
||||
Answered: clk.Now(), Used: clk.Now(),
|
||||
}})
|
||||
@@ -249,7 +249,7 @@ func TestLookupSourceOffLooksNoClientUp(t *testing.T) {
|
||||
)
|
||||
|
||||
// Even an answer kept from before is not used.
|
||||
server.GeoJS.Load([]lookup.Answer{{
|
||||
server.GeoJS.Load([]geojs.Answer{{
|
||||
Client: netip.MustParsePrefix(
|
||||
fromDE + "/32",
|
||||
), ASN: asnDE, ASName: asNameDE,
|
||||
@@ -450,6 +450,8 @@ func TestRequestWaitsAsLongAsTheASNAndCountryLookupTimeoutSays(
|
||||
// network, which would keep that clock from moving on: the request is
|
||||
// handed to waf's handler, and GeoJS is one that never answers.
|
||||
synctest.Test(t, func(t *testing.T) {
|
||||
defer waitForGeoJSRequestsToBeAbandoned()
|
||||
|
||||
// Not the default. The exclusive list needs the answer, and the app
|
||||
// is never reached.
|
||||
const timeout = 3 * time.Second
|
||||
@@ -495,6 +497,17 @@ func TestMain(m *testing.M) {
|
||||
m.Run()
|
||||
}
|
||||
|
||||
// geojsRequestTimeout is how long a request to GeoJS may take before it is
|
||||
// abandoned.
|
||||
const geojsRequestTimeout = 10 * time.Second
|
||||
|
||||
// waitForGeoJSRequestsToBeAbandoned sleeps until every request to the GeoJS at
|
||||
// silentGeoJSURL made so far has been abandoned. A synctest bubble that asks
|
||||
// it defers this: the bubble cannot end while a request waits on it.
|
||||
func waitForGeoJSRequestsToBeAbandoned() {
|
||||
time.Sleep(geojsRequestTimeout)
|
||||
}
|
||||
|
||||
// silentGeoJS is the GeoJS at silentGeoJSURL.
|
||||
type silentGeoJS struct{}
|
||||
|
||||
|
||||
Reference in new issue
Block a user