Delegate GeoIP lookups to hebcal-geoip2 microservice#81
Merged
Conversation
Previously we opened GeoLite2-City.mmdb in-process via the `maxmind`
package, which held the entire ~63 MB database in the heap for the life
of the process even though fewer than ~1 in 500 requests need a GeoIP
lookup (homepage, bare /shabbat, etc.).
Delegate the lookup to the standalone hebcal-geoip2 Go microservice,
which mmaps the database (a few MB resident, shared via the page cache)
and answers GET /lookup?ip= over a Unix domain socket. The web process
now holds no GeoIP database; the trade-off is a ~0.2-0.5 ms loopback
round-trip on the few routes that need it.
- Add src/geoipClient.js: keep-alive HTTP client over the unix socket
with a 20 ms connect timeout. Any error/timeout/non-200 resolves to
null so getLocationFromGeoIp() falls back to {geo:'none'} when the
service is unreachable.
- Rewrite src/geoip.js: setupGeoIp() configures the client (socket path
from hebcal.geoip.socket, or TCP via hebcal.geoip.host/port).
- getLocationFromGeoIp() / getLocationFromQueryOrGeoIp() /
setDefautLangTz() become async; await them in shabbat, converter,
fridge, homepage, and parshaIndex.
- Drop the now-unused `maxmind` dependency.
- Tests for the client (success, 204, service-down fallback, keep-alive)
and updated location tests.
- CLAUDE.md: note the full `npm run build` is required before tests, and
document the new GeoIP architecture.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JdsEBnay9JZScamV9AodLM
|
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.



Summary
Replaces in-process MaxMind GeoIP database lookups with calls to the standalone hebcal-geoip2 Go microservice. This reduces heap memory usage by ~63 MB (the size of GeoLite2-City.mmdb) while maintaining the same geolocation functionality.
Key Changes
New
src/geoipClient.js: HTTP client for the hebcal-geoip2 microservicenullif the service is unreachable or slowRefactored
src/geoip.js: RenamedopenGeoIpDbs()→setupGeoIp()hebcal-dot-com.iniUpdated
src/location.js: MadegetLocationFromGeoIp()andgetLocationFromQueryOrGeoIp()asyncctx.geoipClient.lookup(ip)instead ofctx.geoipCity.get(ip){geo: 'none'}if the client is absent or the lookup failsUpdated callers: Made async where needed
src/defaultLangTz.js:setDefautLangTz()is now asyncsrc/shabbat.js:geoIpRedirect()is now asyncsrc/fridge.js:fridgeIndex()is now asyncsrc/homepage.js,src/parshaIndex.js,src/converter.js: awaitsetDefautLangTz()Removed dependency:
maxmindpackage no longer neededUpdated tests:
test/location.test.jsnow mocksgeoipClient.lookup()instead ofgeoipCity.get()New test:
test/geoipClient.test.jsvalidates the client with a mock HTTP serverDocumentation: Updated
CLAUDE.mdto explain the new architectureImplementation Details
The geoip client uses a promise-based API that never rejects—all errors (connection timeouts, service errors, malformed responses) resolve to
null. This ensures GeoIP is truly best-effort: if the microservice is slow or down, the request handler falls back gracefully without blocking the response.The client manages a single
http.Agentwith keep-alive enabled (maxSockets: 64, maxFreeSockets: 16) to efficiently reuse connections across multiple lookups.https://claude.ai/code/session_01JdsEBnay9JZScamV9AodLM