From 849e8d37133f590dbed7e0a3c86002b37166c566 Mon Sep 17 00:00:00 2001 From: Josh Allmann Date: Fri, 4 Dec 2026 22:45:57 -0800 Subject: [PATCH] Raise discovery response limit to 3 MiB --- discovery/shared/inventory.go | 4 ++-- docs/discovery.md | 4 ++-- docs/signer.md | 2 +- signer/discovery_test.go | 8 ++++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/discovery/shared/inventory.go b/discovery/shared/inventory.go index 0322b53..b420ec8 100644 --- a/discovery/shared/inventory.go +++ b/discovery/shared/inventory.go @@ -10,7 +10,7 @@ import ( "github.com/livepeer/node/destination" ) -const MaxBody = 1 << 20 +const MaxBody = 3 << 20 const ClockSkew = 30 * time.Second // Runner exposes the fields used to validate and compare an inventory record. @@ -34,7 +34,7 @@ func ValidateURL(u *url.URL) error { func Read(body io.Reader) ([]byte, error) { data, err := io.ReadAll(io.LimitReader(body, MaxBody+1)) if err != nil || len(data) > MaxBody { - return nil, errors.New("discovery response unreadable or exceeds 1 MiB") + return nil, errors.New("discovery response unreadable or exceeds 3 MiB") } return data, nil } diff --git a/docs/discovery.md b/docs/discovery.md index 218fbf6..6a6011e 100644 --- a/docs/discovery.md +++ b/docs/discovery.md @@ -28,7 +28,7 @@ Duplicate URLs are skipped. Private sources require returned node metadata are not followed. Refreshes run at startup and every `RefreshInterval` (default `5m`), with at most -five concurrent requests, a three-second timeout, and a 1 MiB limit per response. +five concurrent requests, a three-second timeout, and a 3 MiB limit per response. HTTPS uses system trust. A successful response replaces that source's inventory, including when empty. Failures retain the cached inventory and last successful query time until `MaxFailedRefreshes` consecutive failures (default `6`). Set `0` @@ -54,7 +54,7 @@ discovery has no public identity of its own. See the rules. `AdvertiseNodes` and `AdvertiseRunners` default to `true`; disabling either omits the metadata entry or runner entries, respectively. Disabling both returns `[]` and stops collection. Oversized responses are served with a warning, but -signers reject responses larger than 1 MiB. +signers reject responses larger than 3 MiB. The metrics listener defaults to `127.0.0.1:8940` and serves `/healthz`, `/readyz`, and `/metrics`, including source health, cached inventory, refresh diff --git a/docs/signer.md b/docs/signer.md index f69803a..b905f50 100644 --- a/docs/signer.md +++ b/docs/signer.md @@ -66,7 +66,7 @@ DiscoveryGrants = ["127.0.0.1:8935"] The signer appends `/discovery` to static base URLs and uses webhook URLs unchanged. It polls at startup and every `DiscoveryRefreshInterval` (positive, default `5m`). -Fetches have a five-second timeout and 1 MiB response limit. Failed polls retain +Inventory fetches have a five-second timeout and a 3 MiB limit. Failed polls retain the last inventory until `DiscoveryMaxFailedRefreshes` consecutive failures (default `6`, nonnegative) remove it; `0` evicts on the first failure. Recovered sources reappear on subsequent polls. diff --git a/signer/discovery_test.go b/signer/discovery_test.go index 54b2ecd..80650d6 100644 --- a/signer/discovery_test.go +++ b/signer/discovery_test.go @@ -29,6 +29,7 @@ func discoveryResponse(s *Service, query string) *httptest.ResponseRecorder { func TestSignerDiscovery(t *testing.T) { const advertised = `[{"address":"http://localhost:9000","runners":[{"url":"http://localhost:9000/app","observed_at":"2026-01-01T00:00:00Z","app":"retained","version":"v1","metadata":"model-x","mode":"single-shot","gpu":{"id":"0","name":" H100 ","vram_mb":80000},"capacity":3,"capacity_used":1,"capacity_available":2,"price_info":{"price":10,"price_usd":0.1,"currency":"wei","unit":"fixed"}},{"url":"http://localhost:9000/cpu","observed_at":"2026-01-01T00:00:00Z","app":"cpu","mode":"single-shot","capacity":1,"price_info":{"price":1,"currency":"wei","unit":"fixed"}}]}]` + const maxBytes = 3 << 20 bodies := map[string]string{ "empty": "[]", "good": advertised, "failed": "", "malformed": "not JSON", "lenient": strings.NewReplacer( @@ -38,8 +39,10 @@ func TestSignerDiscovery(t *testing.T) { `"app":"cpu",`, `"app":"cpu","version":null,"metadata":null,"gpu":null,"capacity_used":null,"capacity_available":null,`, ).Replace(advertised), "metadata": `[{"nodes":[]}]`, - "truncated": `[{"address":`, "oversized": `[{"address":"` + strings.Repeat("a", 1<<20) + `"}]`, - "invalid": `[{"address":"file:///invalid","runners":[{"url":"http://localhost/app","app":"example"}]},{"address":"https://orch.example","runners":[{"url":"http://localhost/app"},{"app":"example"}]}]`, + "truncated": `[{"address":`, + "max-size": advertised + strings.Repeat(" ", maxBytes-len(advertised)), + "oversized": advertised + strings.Repeat(" ", maxBytes+1-len(advertised)), + "invalid": `[{"address":"file:///invalid","runners":[{"url":"http://localhost/app","app":"example"}]},{"address":"https://orch.example","runners":[{"url":"http://localhost/app"},{"app":"example"}]}]`, } var connections atomic.Int32 server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -102,6 +105,7 @@ func TestSignerDiscovery(t *testing.T) { {[]string{"metadata"}, "", 200, nil}, {[]string{"failed"}, "", 503, nil}, {[]string{"malformed"}, "", 503, nil}, {[]string{"truncated"}, "", 503, nil}, {[]string{"oversized"}, "", 503, nil}, + {[]string{"max-size"}, "", 200, []string{"retained", "cpu"}}, {[]string{"denied", "failed", "malformed", "good"}, "", 200, []string{"retained", "cpu"}}, {[]string{"collected"}, "", 200, []string{"retained", "cpu"}}, {[]string{"lenient"}, "", 200, []string{"retained", "cpu"}},