Skip to content

Commit

Permalink
Update caddywaf.go
Browse files Browse the repository at this point in the history
Minor improvement.
  • Loading branch information
fabriziosalmi authored Jan 6, 2025
1 parent 51878f3 commit d8c618a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions caddywaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,41 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
}

func (m *Middleware) Shutdown(ctx context.Context) error {
// Log the start of the shutdown process
m.logger.Info("Shutting down WAF middleware")

// Signal the rate limiter cleanup goroutine to stop
if m.rateLimiter != nil {
m.logger.Debug("Stopping rate limiter cleanup goroutine")
m.rateLimiter.signalStopCleanup()
}

// Close the GeoIP database if it is open
if m.CountryBlock.geoIP != nil {
m.logger.Debug("Closing country block GeoIP database")
if err := m.CountryBlock.geoIP.Close(); err != nil {
m.logger.Error("error closing country block geoip database", zap.Error(err))
m.logger.Error("Failed to close country block GeoIP database",
zap.Error(err),
)
return fmt.Errorf("failed to close country block GeoIP database: %w", err)
}
m.CountryBlock.geoIP = nil // Ensure the reference is cleared
}

if m.CountryWhitelist.geoIP != nil {
m.logger.Debug("Closing country whitelist GeoIP database")
if err := m.CountryWhitelist.geoIP.Close(); err != nil {
m.logger.Error("error closing country whitelist geoip database", zap.Error(err))
m.logger.Error("Failed to close country whitelist GeoIP database",
zap.Error(err),
)
return fmt.Errorf("failed to close country whitelist GeoIP database: %w", err)
}
m.CountryWhitelist.geoIP = nil // Ensure the reference is cleared
}

// Log the successful completion of the shutdown process
m.logger.Info("WAF middleware shutdown complete")

return nil
}

Expand Down

0 comments on commit d8c618a

Please sign in to comment.