Repository navigation
fix(local-api): probe the collections list, so a large library cannot hide a running Zotero (#102) - #103
Merged
Conversation
… hide a running Zotero (#102) The liveness probe asked the desktop app for /users/0/items?limit=1 with a 1.5 s budget (2 s at startup). Zotero answers that request by running a library-wide search, loading every item it returns and sorting them all before it slices off one, so the cost is the size of the library whatever the limit says. On a library of 166,338 items every probe timed out, the local API was reported absent for the life of the process, and every read went to the cloud Web API, where a library-wide full-text search then timed out. curl has no budget, which is why it "worked". The probe now asks for /users/0/collections?limit=1: the same endpoint class, so a switched-off local API still answers 403 and a proxy that rewrites the Host header still answers 400, over a list that is a few hundred entries at most. Zotero 10 desktop writes read their server id and library version off the same request, since both headers come on every local API response. The probe's outcome is now kept on the live capability object and reported: the startup Capabilities line says why localApi is false, and zotero_whoami carries localApiProbe (unreachable, timeout with its budget, or the HTTP status Zotero answered) and chooses its remedy by it. The reporter's two theories (a browser User-Agent, an IPv6 localhost) were both already impossible, and a bare `localApi: false` gave nothing to rule them out with.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #102.
What was wrong
The local API liveness probe asked Zotero for
/api/users/0/items?limit=1with a 1.5 s budget (2 s at startup). Zotero answers that request by running a library-wide search, loading every item it returns and sorting them all, and only then slicing off one item (server_localAPI.js,LocalAPIEndpoint.initandItems._runGet). So the request costs the size of the library, whatever thelimitsays. On the reporter's 166,338 items every probe ran out of budget,localApistayedfalsefor the life of the process, and every read went to the cloud, where the library-wide full-text search timed out.curlhas no budget, which is why it "worked".Both theories in the report were already ruled out by the code: the desktop transport is
node:http, which sends noUser-Agent, and every request carriesx-zotero-connector-api-version, which is precisely the header Zotero's browser check exempts (server.js,_processEndpoint). The base URL has been127.0.0.1since the first release. A barelocalApi: falsegave the reporter nothing to rule either out with.What changes
ping, and the Zotero 10 write client's own probe) ask for/api/users/0/collections?limit=1. Same endpoint class, so a switched-off local API still answers 403 and a proxy rewriting the Host header still answers 400, and the sameLast-Modified-VersionandZotero-Server-IDheaders come back. Cost: a few hundred entries at most.Capabilitiesobject (localProbe):up,unreachable,timeoutwith its budget, orhttpwith the status.Capabilities: cloud=none, localApi=false (nothing listening on 127.0.0.1:23999), localGroups=0.zotero_whoamireportslocalApiProbeand chooses its remedy by it: a 403 is "Zotero is running but its local API is switched off", a timeout names the budget and where Zotero's debug output shows its own timing, a refused connection names the port andZOTERO_LOCAL_PORT.Verified
node dist/index.jsover stdio with the real Zotero:localApi: true,localApiProbe: {"kind":"up"}. Against a dead port:localApi: false,localApiProbe: {"kind":"unreachable"}, and the summary names the port andZOTERO_LOCAL_PORT.npm test: 2751 passed, 8 skipped.typecheck,typecheck:testsand eslint on the changed files are clean.Not shipped here: a settings-pane field for the port.
ZOTERO_LOCAL_PORTexists and is documented; Zotero only listens on loopback, so there is no base URL to configure beyond it.