Skip to content

refactor: explain why mapping the IP databases is sound - #1682

Merged
monosans merged 1 commit into
mainfrom
refactor/ipdb-mmap-safety
Nov 12, 2026
Merged

monosans merged 1 commit into
mainfrom
refactor/ipdb-mmap-safety

Conversation

@monosans

Copy link
Copy Markdown
Owner

Summary

I went over everything that touches maxminddb after the bump to 0.33.0. The calls (open_mmap, lookup, LookupResult::decode, the geoip2 types) already match the current API, and nothing in the 0.31 to 0.33 upgrade notes affects us: we don't write newtype visitors, and a record that hits the new decode limits only costs that proxy its data, which a test already covers.

The one thing left was the unsafe mmap open, which silenced clippy::undocumented_unsafe_blocks instead of saying why it's sound. It now has a SAFETY comment: a database file is never written after it's mapped, because a download fills the temp file before checking it and then renames it into place.

I also measured the lookups against the current GeoLite2 City and ASN databases (release build, 20,000 random IPv4 addresses):

  • opening both databases: 0.4 ms
  • ASN and City lookup, decode, English-only names and JSON for all 20,000: about 30 ms
  • Reader::verify() would add 305 ms (City) and 37 ms (ASN) per download

So the lookups don't need optimising, even though both JSON files repeat them. I left verify() out: TLS and the length check already catch a damaged download, and the verifier is stricter than the format spec, so it could turn away a database that works.

Testing

  • cargo +beta clippy --all-targets --features tui -- and cargo +beta clippy --all-targets -- pass. Clippy would flag the block if the comment weren't recognised.
  • cargo +nightly fmt --check and uvx prek run --all-files pass.
  • cargo +beta test --locked -- ipdb output passes.

Checklist

  • uvx prek run --all-files passes.
  • cargo +nightly fmt --check passes.
  • cargo +beta clippy --all-targets --features tui -- and cargo +beta clippy --all-targets -- pass.
  • cargo +beta test --features tui --locked and cargo +beta test --locked pass, and new behavior has tests.
  • config.toml, config-schema.json and README.md match any change to the options or the output.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Chores
    • Updated code safety lint checks; existing safety rationale remains.

The mmap-opening unsafe block continues to suppress the unsafe_code lint. Its annotation no longer suppresses Clippy’s undocumented-unsafe-block lint. The safety rationale remains in comments.

Changes: Unsafe block lint

Layer / File(s) Summary
Lint annotation
src/ipdb.rs
The mmap-opening unsafe block’s annotation now suppresses only the unsafe_code lint. The safety explanation remains in comments.

Possibly related PRs

Change: Other

Merge Risk: Minimal · up to e7aa9

This change only adjusts a lint annotation and the safety comment on the database open. It does not change runtime behavior, so there is no meaningful merge risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses the Conventional Commits 'refactor:' prefix and describes the main change: a SAFETY comment explaining why memory-mapping the IP databases is sound. The raw summary confirms the only co…
Description check Passed The description follows the template well. It has a Summary explaining the change and why, including the SAFETY rationale and the upgrade review. It has a Testing section listing the commands run. The…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title uses the Conventional Commits 'refactor:' prefix and describes the main change: a SAFETY comment explaining why memory-mapping the IP databases is sound. The raw summary confirms the only code change is in src/ipdb.rs, where the open_reader annotation now suppresses only unsafe_code and the rationale is kept in comments. The title is specific and related to the changeset. Note that the change removes a clippy suppression rather than adding new code, so 'refactor' is a reasonable fit.

Full details: Description check

Explanation

The description follows the template well. It has a Summary explaining the change and why, including the SAFETY rationale and the upgrade review. It has a Testing section listing the commands run. The checklist is filled in, with the test-suite items left unchecked. The Related issues section is missing, but the template says to remove it when there are none, so that omission is acceptable. The description does not link any issue, and the template's Related issues section is optional. The unchecked test item is a gap, since the template says new behavior needs tests. This change adds no new behavior, so the gap is minor. The description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 91999d01-4483-424d-ab18-dc2d2fe814fa
Commits

Reviewing files that changed from the base of the PR and between 4e2f6de and e7aa9e6.

Files selected for processing: 1

  • src/ipdb.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@monosans
monosans merged commit d0b1f26 into main Nov 12, 2026
75 checks passed
@monosans
monosans deleted the refactor/ipdb-mmap-safety branch November 12, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant