Unreachable audit log forward endpoint blocks configuration writes for minutes
An unreachable audit log forward endpoint wedges configuration writes for many minutes. Every syslog connect waits out the kernel's TCP connect timeout (about 2 minutes on Linux). A configuration update makes two such connects while its request transaction holds the properties row locks, and every audit event connects again because LoggerManager never remembers the endpoint it dialled. We found this while chaos testing https://github.com/goharbor/harbor/pull/23996 on a dev cluster.
What we saw
- Harbor core ran 3 replicas, with a pool of 20 connections each.
audit_log_forward_endpointwas set to an address that drops packets (10.255.255.1:1), while config writes and push/pull load kept running.- Configuration requests then hung well past their clients' 10 second timeout.
- After 10 minutes, one transaction was still
idle in transaction, holding the row locks foraudit_log_forward_endpointandbanner_message. Its last statement was the settings save. - 31 further configuration transactions queued behind it on those row locks. Each of them held a database connection out of the 60 the three pods had in total.
- Nothing recovered by itself. We had to terminate the stuck sessions with
pg_terminate_backendand clear the endpoint in SQL. - Every pod logged
failed to create audit log, error dial tcp 10.255.255.1:1: connect: connection timed outfor write requests, each about 2 minutes after the event.
Cause
In src/pkg/audit/forward.go:
LoggerManager.InitandCheckEndpointActivecallsyslog.Dial("tcp", endpoint, ...), which has no timeout, so an unreachable address blocks each call for the kernel's full SYN retry time.DefaultLoggercallsInitwhenevera.endpointdiffers from the configured endpoint, but nothing ever assignsa.endpoint. With any endpoint set, every audit event dials again.LoggerManageris shared by all goroutines and has no lock, so theseInitcalls race.
In src/controller/config/controller.go, UpdateUserConfigs saves the settings first, then calls updateLogEndpoint. That runs CheckEndpointActive and LogMgr.Init, both inside the request transaction, so the row locks from the save are held for both dials.
Steps to reproduce
- Run Harbor core with an external Postgres and some write load.
- As admin,
PUT /api/v2.0/configurations {"audit_log_forward_endpoint":"10.255.255.1:1"}, an address that drops packets rather than refusing them. - Keep sending configuration updates (for example
banner_message) and push images. - Watch
pg_stat_activity: configuration transactions pile up inLock/tuplebehind one transaction that staysidle in transaction.
Suggested fix
- Dial with a timeout (
net.Dialer{Timeout: ...}and a syslog writer on top of that connection). - Set
a.endpointinInit, and guardLoggerManagerwith a mutex. - Check the endpoint before saving the settings, outside the transaction.
- Forward audit events through a bounded buffer instead of on the request goroutine.
Benefits
- A slow or unreachable SIEM can no longer stall configuration changes or tie up database connections.
- Audit forwarding stops reconnecting on every event, which also removes a data race.
- Admins get a quick error for a bad endpoint instead of a request that hangs for minutes.
Versions: main (src/pkg/audit/forward.go, src/controller/config/controller.go).
Source: goharbor/harbor