Commit Graph
38 Commits
Author SHA1 Message Date
claudecodeandClaude 80aa464e09 Address codex review (#22): client IP validation, updated_at, merge robustness
1. /json client IP (codex #1, Medium): HandleJson now validates
   c.ClientIP() and returns 400 on a malformed value instead of letting
   Query fail into a 500. HandleIpInfo gained a selfLookup flag so a valid
   but DB-absent self-IP preserves the 9d07639 graceful 200 {"ip": ip}
   default (private/loopback addresses are never in a public GeoIP DB),
   while the explicit /:ip route still returns 404 on not-found.

2. updated_at=0 on initial load (codex #2, Low): stampDbUpdatedAt() now
   records the canonical mmdb's mtime both on initial load (existing
   files) and after each successful update, so /metrics never reports 0
   while serving real data.

3. Merge corruption -> permanent outage: mmdbmeld.WriteMMDB truncates the
   canonical mmdb before writing; a failed merge previously left it empty
   and the saved etag made the next daily run 304-skip the retry, so a
   restart failed to open the file and the service went 503 permanently.
   fetchDbs now backs up the canonical file before merge, restores it on
   merge/reload failure, and drops the etags so the next run retries.

4. Temp-file leaks: Reload removes the temp clone and restores d.dbFile
   when reader.Open fails (it previously assigned d.dbFile before Open);
   cloneDBFile removes the temp on a failed copy.

Verified: go build, go vet, gofmt -l, go test -race ./... all pass.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-22 17:11:58 +07:00
claudecodeandClaude e2b0732014 Fix data races, robustness, and cleanup across codebase (#10-#21)
Concurrency & correctness:
- #10: guard IpDb Query/IsLoaded with RLock so Reload() (which reassigns d.r
  and closes the old reader) cannot race with concurrent lookups. Confirmed
  via -race regression test.
- #12: replace DbUpdatedAt time.Time with atomic.Int64 (cron writes,
  /metrics reads) to fix the read/write data race.
- #11: graceful HTTP shutdown (srv.Shutdown with 10s timeout) instead of
  srv.Close() aborting in-flight requests.
- #14: stop swallowing mergeMmdb() errors in fetchDbs() — keep the previous
  DB when a merge fails instead of reloading a possibly-empty output.
- #13: add resty timeout (2m) + retry (x2) to download() so a hung CDN can't
  stall the daily cron forever.
- #15: correct HTTP status codes (503 db loading, 404 not found via new
  ErrNotFound sentinel, 500 otherwise) instead of 200 on query error.

Robustness:
- #16: surface osx.Copy dstFile.Close() errors (flush may fail) via named
  return + defer.

Dependency migration:
- #17: migrate maxminddb-golang v1 -> v2. v2 is a breaking API
  (LookupNetwork -> Lookup returning Result, netip.Addr), so Query was
  rewritten; v1 dropped from go.mod.

Tests:
- #21: add internal/data unit tests (valid/invalid/not-found lookup) plus a
  concurrent Query/Reload race regression test. chdir to repo root in TestMain
  because data helpers use relative paths.

Cleanup:
- #18: README Go version 1.22 -> 1.25.
- #19: replace stray fmt.Printf with zerolog in ipdb.go.
- #20: .env.example API_PORT 28080 -> 8080 (container port, matches
  docker-compose 28080:8080 mapping) with an explanatory comment.

Closes #10, #11, #12, #13, #14, #15, #16, #17, #18, #19, #20, #21

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-22 06:37:40 +00:00
codex d05ab4b402 update dep
Build Docker Image / build (arm64) (push) Successful in 1m44s
Build Docker Image / build (amd64) (push) Successful in 4m41s
Build Docker Image / amend-manifest (push) Successful in 11s
2026-07-09 10:40:13 +07:00
thuanle 0146e6446a Merge pull request 'Update module github.com/go-resty/resty/v2 to v2.17.2' (#5) from renovate/github.com-go-resty-resty-v2-2.x into main
Build Docker Image / build (arm64) (push) Failing after 37s
Build Docker Image / build (amd64) (push) Failing after 1m11s
Build Docker Image / amend-manifest (push) Has been skipped
Reviewed-on: #5
2026-07-06 10:13:36 +07:00
thuanle afa8ba4dba Merge pull request 'Update module github.com/rs/zerolog to v1.35.1' (#7) from renovate/github.com-rs-zerolog-1.x into main
Build Docker Image / build (arm64) (push) Failing after 34s
Build Docker Image / build (amd64) (push) Failing after 1m13s
Build Docker Image / amend-manifest (push) Has been skipped
Reviewed-on: #7
2026-07-06 10:13:02 +07:00
thuanle 75c4366a34 Merge pull request 'Update module github.com/oschwald/maxminddb-golang to v2' (#8) from renovate/github.com-oschwald-maxminddb-golang-2.x into main
Build Docker Image / build (arm64) (push) Failing after 32s
Build Docker Image / build (amd64) (push) Failing after 1m7s
Build Docker Image / amend-manifest (push) Has been skipped
Reviewed-on: #8
2026-07-06 10:12:54 +07:00
Renovate Bot d73dd1b5e8 Update module github.com/oschwald/maxminddb-golang to v2
renovate/artifacts Artifact file update failure
2026-07-04 17:02:48 +00:00
Renovate Bot 602e579365 Update module github.com/rs/zerolog to v1.35.1
renovate/artifacts Artifact file update failure
2026-07-04 17:02:46 +00:00
Renovate Bot 0b7d66cec0 Update module github.com/go-resty/resty/v2 to v2.17.2
renovate/artifacts Artifact file update failure
2026-07-04 17:02:43 +00:00
thuanle cc5cf67c88 Update renovate.json
Build Docker Image / build (arm64) (push) Successful in 1m16s
Build Docker Image / build (amd64) (push) Successful in 1m54s
Build Docker Image / amend-manifest (push) Successful in 11s
2026-07-03 10:17:02 +07:00
claudecodeandClaude 7f78bdd23d fix(ci): regenerate go.sum for robfig/cron/v3 v3.0.1
Build Docker Image / build (arm64) (push) Successful in 1m2s
Build Docker Image / build (amd64) (push) Successful in 1m59s
Build Docker Image / amend-manifest (push) Successful in 9s
Renovate bumped github.com/robfig/cron/v3 to v3.0.1 in go.mod (edde31c)
without regenerating go.sum, leaving only the v3.0.0 hash. The Docker CI
build (go build -mod=readonly) then failed with 'missing go.sum entry for
module providing package github.com/robfig/cron/v3' on both amd64/arm64.

Run go mod tidy to regenerate go.sum (also corrects indirect markers and
drops the unused spaolacci/murmur3 entry). Verified the exact CI build
command now passes locally.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-16 21:11:40 +07:00
thuanle 403d2d7ea1 Merge pull request 'Update golang Docker tag to v1.26' (#3) from renovate/golang-1.x into main
Build Docker Image / build (arm64) (push) Failing after 37s
Build Docker Image / build (amd64) (push) Failing after 35s
Build Docker Image / amend-manifest (push) Has been skipped
Reviewed-on: #3
2026-06-16 20:38:57 +07:00
thuanle 9f108eb294 Merge pull request 'Update module github.com/robfig/cron/v3 to v3.0.1' (#2) from renovate/github.com-robfig-cron-v3-3.x into main
Build Docker Image / build (amd64) (push) Failing after 25s
Build Docker Image / build (arm64) (push) Failing after 39s
Build Docker Image / amend-manifest (push) Has been skipped
Reviewed-on: #2
2026-06-16 20:38:46 +07:00
Renovate Bot d02567b385 Update golang Docker tag to v1.26 2026-06-13 17:01:46 +00:00
Renovate Bot edde31c308 Update module github.com/robfig/cron/v3 to v3.0.1
renovate/artifacts Artifact file update failure
2026-06-13 17:01:44 +00:00
thuanle 1138ed8011 Merge pull request 'Configure Renovate' (#1) from renovate/configure into main
Build Docker Image / build (arm64) (push) Successful in 40s
Build Docker Image / build (amd64) (push) Successful in 1m23s
Build Docker Image / amend-manifest (push) Successful in 5s
Reviewed-on: #1
2026-06-08 07:04:35 +07:00
Renovate Bot 2fc7b2940c Add renovate.json 2025-10-25 17:00:57 +00:00
thuanle 1ef2896fb1 query other ip
Build Docker Image / build (arm64) (push) Successful in 36s
Build Docker Image / build (amd64) (push) Successful in 4m18s
Build Docker Image / amend-manifest (push) Successful in 16s
2025-10-13 17:27:14 +07:00
thuanle f89394be9c fix docker file
Build Docker Image / build (arm64) (push) Successful in 50s
Build Docker Image / build (amd64) (push) Successful in 2m5s
Build Docker Image / amend-manifest (push) Successful in 6s
2024-11-07 09:17:39 +07:00
thuanle 108458682e add Metric
Build Docker Image / build (arm64) (push) Successful in 54s
Build Docker Image / build (amd64) (push) Successful in 2m13s
Build Docker Image / amend-manifest (push) Successful in 5s
2024-11-07 09:08:19 +07:00
thuanle b0ac68cbdb update ignore 2024-11-07 08:56:28 +07:00
thuanle 4752849f9d log done 2024-08-05 15:23:57 +07:00
thuanle 518f389e73 create data folder 2024-08-05 15:16:24 +07:00
thuanle f33d064d6e tune update db 2024-08-05 15:06:39 +07:00
thuanle 71ceabdf00 do not rebuild db if no new file 2024-07-24 08:25:09 +07:00
thuanle d4d38b478b fix asn not download 2024-07-20 23:47:08 +07:00
thuanle a6d2b658d0 fix download with etag 2024-07-14 01:54:13 +07:00
thuanle 985e710dbe docker compose 2024-07-14 00:58:52 +07:00
thuanle eaeb32b421 etag write to file
handle query before db loaded
2024-07-14 00:48:58 +07:00
thuanle 12603bbf6c docker file 2024-07-14 00:25:10 +07:00
thuanle 14a4484c6c docker file 2024-07-14 00:22:21 +07:00
thuanle 83389a4569 docker file 2024-07-14 00:21:13 +07:00
thuanle 1fb71e14c4 fix go mod 2024-07-14 00:19:20 +07:00
thuanle 9d07639d6c default value when lookup internal ip 2024-07-14 00:17:51 +07:00
thuanle cc8449c7b3 dockerize 2024-07-14 00:14:25 +07:00
thuanle 1307a1ba29 fix not close db 2024-07-14 00:06:10 +07:00
thuanle 4bb5ee09f0 first commit 2024-07-13 23:58:47 +07:00
ThuanLe 5a47b94c85 Initial commit 2024-07-13 21:11:22 +07:00