oschwald / maxminddb-golang

MaxMind DB Reader for Go
ISC License
570 stars 99 forks source link

Build tag 'maxminddisablemmap' to disable mmap() even when supported #139

Closed garnould closed 3 weeks ago

garnould commented 3 weeks ago

Adding a build tag 'maxminddisablemmap' to force in-memory loaded database, even when mmap() is supported.

Maxmind database file content (ex: GeoIP2-Country.mmdb) being modified/updated 'on the fly' while it is opened by Reader with mmap() can lead to unexpected and catastrophic behaviour.

This patch modifies slightly "reader_memory.go" & "reader_mmap.go" to provide a way to disable mmap() usage in maxminddb-golang, using '-tags maxminddisablemmap' (ex: go run -tags maxminddisablemmap)

oschwald commented 3 weeks ago

Why not just read in the file and use FromBytes instead of Open?

Yes, modifying an opened mmap'd file will cause issues, but you shouldn't need to modify a file in the first place. If you are updating the database to a new version, I would suggest atomically replacing the file, which won't modify the existing mapped data.

garnould commented 3 weeks ago

Hi Gregory,

I completely missed the point I could use FromBytes() instead of Open(), which will do the job perfectly.

Sorry for this unusefull PR, and thank you for your work and this really helping answer :)

garnould commented 3 weeks ago

Closing this PR