Problem
The Fiber client (client/core.go:156-193) holds a write lock (c.client.mu.Lock()) while executing pre-hooks and post-hooks. This means:
- Hook functions execute while holding the write lock.
- Concurrent requests through the same client serialize on hook execution.
- User hooks that perform I/O (logging, metrics) block all other requests.
Proposed fix
Snapshot the hook slices under the lock, then execute without it:
func (c *Core) preHooks(req *Request) {
c.client.mu.RLock()
hooks := c.client.preHooks // slice header copy
c.client.mu.RUnlock()
for _, hook := range hooks {
hook(req)
}
}
Use RLock for reads (hook execution) and reserve Lock only for mutation (adding/removing hooks).
Priority
P1 — Matters for high-throughput client usage with concurrent requests.
Identified during a full performance architecture review of the Fiber codebase.
Problem
The Fiber client (
client/core.go:156-193) holds a write lock (c.client.mu.Lock()) while executing pre-hooks and post-hooks. This means:Proposed fix
Snapshot the hook slices under the lock, then execute without it:
Use
RLockfor reads (hook execution) and reserveLockonly for mutation (adding/removing hooks).Priority
P1 — Matters for high-throughput client usage with concurrent requests.
Identified during a full performance architecture review of the Fiber codebase.