mirror of
https://github.com/therootcompany/golib.git
synced 2026-11-04 06:55:00 +00:00
fix(dataset): guard typed-nil previous value when closing replaced view
`any(typedNilPtr)` wraps the nil pointer in a non-nil interface, so the prior `closer != nil` check didn't catch it — calling Close on the underlying nil *geoip.Databases segfaulted during the first successful reload after a failed one. Also flip form2mail's default blocklist URL from git@ (SSH) to https:// so fresh deployments work without a GitHub SSH key.
This commit is contained in:
parent
950aea9eeb
commit
9e46d5ce90
@ -33,7 +33,7 @@ const (
|
||||
licenseOwner = "AJ ONeal"
|
||||
licenseType = "CC0-1.0"
|
||||
|
||||
defaultBlocklistRepo = "git@github.com:bitwire-it/ipblocklist.git"
|
||||
defaultBlocklistRepo = "https://github.com/bitwire-it/ipblocklist.git"
|
||||
refreshInterval = 47 * time.Minute
|
||||
|
||||
requestsPerMinute = 5
|
||||
|
||||
@ -186,10 +186,15 @@ func (v *View[T]) reload(ctx context.Context) error {
|
||||
// Close the replaced value if it holds OS resources (open file handles,
|
||||
// network connections). Geoip readers and similar wrappers implement
|
||||
// io.Closer; cohort and other pure-in-memory values don't — the type
|
||||
// assertion filters to only the ones that need it.
|
||||
if closer, ok := any(prev).(io.Closer); ok && closer != nil {
|
||||
// assertion filters to only the ones that need it. The `prev != nil`
|
||||
// guard is required because any(typedNilPtr) is a non-nil interface
|
||||
// wrapping a nil pointer — the type assertion succeeds and we'd
|
||||
// call Close on a nil receiver.
|
||||
if prev != nil {
|
||||
if closer, ok := any(prev).(io.Closer); ok {
|
||||
_ = closer.Close()
|
||||
}
|
||||
}
|
||||
now := time.Now()
|
||||
v.loadedAt.Store(&now)
|
||||
return nil
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user