ac4af582301a4e8a29245dbba767eba31334ddf9
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
4725c772bb |
netproxy: a hung system proxy read holds no request; a failed one keeps the last proxy (#3421)
System() ran readSystem under sysCache's lock, and on macOS that is scutil --proxy, started with proc.Command and no timeout. When neither magpie's settings nor the environment name a proxy, every request's proxy comes from there (For, through Func: http.DefaultTransport, the gateway's upstream transport, MCP, updates), so a scutil that never answered held each of them on that lock for as long as it hung, past its own deadline too: net/http looks at a request's context before it calls Proxy, not while. With no system proxy set, scutil runs again every 2 s it is asked. And a read that failed was taken as no proxy: where vendors are reached only through the system's proxy, a scutil that failed once sent the next 2 s of requests direct. The code standards' "nothing that can block runs under a lock its reader needs" and "a failed read means unknown". Found while chasing #3362, an app whose partner fetch never came back. Nothing there shows scutil was what hung; it is the one wait on that path with no end. Now: - One read runs at a time, outside the lock. A request waits for it until readWait (2 s) after it began, then takes what was read before. Before the first read that is nothing, so direct, as a failed first read was. A read already past readWait holds nobody. - A read that fails keeps what was read before, and the read after it holds nobody either: requests go on with the proxy read before until a read answers. - scutil gets toolWait (10 s) and is then ended (readTool, through proc.CommandContext), and that read fails. - Windows' registry: a key or value that isn't there is no proxy, as before; any other error is a failed read. Elsewhere there is no system proxy to read, and nothing changes. ggbdpq's patch on #2562 has testenv stand in for scutil with exit 1. Under this change that read fails with nothing read before it, which is still no proxy, so it does what it did. What was run (tree 6f5e4b92, on |
||
|
|
e9221e96dd |
provider, netproxy, gui: allowances can be read only when asked, and a system proxy set after start is taken within seconds (#1518, RooobinYe)
The reporter starts magpie at login with the proxy on "follow system
proxy". magpie comes up before the proxy app. With no system proxy set
yet, netproxy.For gives none, so magpie's own allowance reads went out
direct, from the user's real IP. That reading was then kept for up to
15s. A system proxy that is set but not listening fails the request
("proxyconnect ... connection refused"); it never falls back to direct.
Proxy freshness:
- netproxy.System re-reads a "none" reading after 2s (noneKeep) instead
of 15s (systemKeep, unchanged for a set proxy).
- The plugin host looks again every 2s while it has no proxy
(proxyLookNone), so a host started before the proxy app takes it soon.
- Catalog sync, the update check, plugin updates and token refresh all go
through netproxy.Func / Dispatch, so they use the current proxy too.
Settings -> Allowances -> "Allowance reads": Automatic (default, as
before) or When I ask (settings.QuotaReads = "asked",
POST /api/settings/quota-reads):
- These count as asking (provider.Asked): the Usage page opened or
refreshed (?asked=1), a card's refresh (RefreshUsage), magpie quota,
magpie accounts, magpie quota wait and the TUI's quotas.
- Every other read (quotaReading -> holdUnasked) carries netproxy.Hold.
netproxy.Func, Dispatch's choice proxies and the plugin host's calls
refuse a held request before it leaves.
- The readers return the last reading, dated (AsOf), or "not read yet".
That covers routing's Allowances / AwaitAllowance, the used-up switch,
the menu bar, alerts, Quotas/KeyBalances/PlanQuotas, Codex/Claude/
Cursor/Grok/Kiro usage and KeyAllowance.
- An account refused for its quota (StaleAllowance) or a key refused
(StaleKeyAllowance) is still read, once.
- Warm-up and check-in are unchanged.
- Strings are added in zh, zh-TW, ja and de. The docs are updated:
providers-accounts (Allowance row), provider-plugins (host proxy).
Run:
- go test -tags nogui ./... (sandbox HOME), gofmt -l, and go vet -tags
nogui on GOOS=linux/windows/darwin for ., netproxy, plugin, settings,
provider, gui and tui.
- New tests, each seen red by breaking the change by hand:
- TestSystemProxySetAfterStartIsTakenSoon and TestHeldRequestNeverLeaves
(netproxy).
- TestHostWithNoProxyLooksAgainSoon (plugin; red with 15s).
- TestAllowancesReadOnlyWhenAsked (red without the hold and without
markStaleRead), TestAllowancesReadByThemselvesByDefault and
TestKeyReadsOnlyWhenAsked (red without holdUnasked and without
unheld for a refused key).
- GUI quota-reads.test.cjs in Chromium and WebKit, at 900 and 360px, in
en/zh/zh-TW/ja/de.
- i18n-keys, gui-ja, gui-de, settings-sections, settings-groups,
currency, number-units and tray-bird.
|