pool/worker: add EventDialFailed with per-attempt error

This commit is contained in:
Jay
2026-06-04 19:34:40 -04:00
parent a574b3e5ae
commit a6d412c31d
3 changed files with 170 additions and 5 deletions
+10 -2
View File
@@ -311,8 +311,15 @@ func (w *DefaultWorker) spawnDialer(
w.logger.Debug("session: dialing")
}
onDialError := func(err error) {
if dialCtx.Err() != nil {
return
}
pool.Events <- PoolEvent{ID: w.id, Kind: EventDialFailed, Err: err, At: time.Now()}
}
go func() {
conn, err := connect(w.id, dialCtx, pool, w.handler)
conn, err := connect(w.id, dialCtx, pool, w.handler, onDialError)
if err != nil {
return
@@ -333,13 +340,14 @@ func connect(
ctx context.Context,
pool PoolPlugin,
handler slog.Handler,
onDialError func(error),
) (*transport.Connection, error) {
cc := pool.ConnectionConfig
conn, err := transport.NewConnection(ctx, id, &cc, handler)
if err != nil {
return nil, err
}
return conn, conn.Connect(ctx, nil)
return conn, conn.Connect(ctx, onDialError)
}
// ---------------------------/