Skip to content

Commit e336bd5

Browse files
committed
fix(http): avoid typed-nil pool panic on Serve failure; clarify attr error
NewPool returns a concrete *static_pool.Pool, so assigning its result directly to the api.Pool interface field on the error path boxed a typed nil into p.pool. The simplified Stop guard (`if p.pool != nil`) then sees a non-nil interface and calls Destroy on the nil receiver, which panics (Destroy dereferences sp.log immediately). Assign to p.pool only when the returned pointer is non-nil so the interface never holds a typed nil and the existing guard stays correct. Also distinguish the wrong-type case in attributes.Set from the missing-key case with its own error message for easier diagnosis.
1 parent ba9070b commit e336bd5

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

attributes/attributes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func Set(r *http.Request, key string, value string) error {
8989

9090
a, ok := v.(attrs)
9191
if !ok {
92-
return errors.New("unable to find `psr:attributes` context key")
92+
return errors.New("unexpected type stored under `psr:attributes` context key")
9393
}
9494
a.set(key, value)
9595
return nil

plugin.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,18 @@ func (p *Plugin) Serve() chan error {
127127
p.mu.Lock()
128128
defer p.mu.Unlock()
129129

130-
var err error
131-
p.pool, err = p.server.NewPool(context.Background(), p.cfg.Pool, map[string]string{RrMode: RrModeHTTP}, p.log)
130+
// NewPool returns a concrete *static_pool.Pool; assign it to the api.Pool
131+
// interface field only when non-nil so p.pool never holds a typed nil
132+
// (which would make the p.pool != nil guard in Stop spuriously true and
133+
// panic inside Destroy on a nil receiver).
134+
np, err := p.server.NewPool(context.Background(), p.cfg.Pool, map[string]string{RrMode: RrModeHTTP}, p.log)
132135
if err != nil {
133136
errCh <- err
134137
return errCh
135138
}
139+
if np != nil {
140+
p.pool = np
141+
}
136142

137143
// request queue + worker-facing ConnectRPC server
138144
p.queue = proxy.NewQueue(p.cfg.Proxy.InboxSize)

0 commit comments

Comments
 (0)