refactor: hoist SSE client to struct, split RPC and SSE HTTP clients

The SSE client (no timeout, long-lived stream) was recreated on every
reconnect, wasting connection pool resources. Hoist it to the struct
alongside the RPC client (30s timeout) so connections can be reused.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Achton Smidt Winther 2026-02-28 11:55:28 +01:00
parent b5bd7985c6
commit af25536c19
No known key found for this signature in database
GPG key ID: B2C1917109213BD1

View file

@ -40,7 +40,8 @@ const (
type SignalChannel struct {
*channels.BaseChannel
config config.SignalConfig
httpClient *http.Client
rpcClient *http.Client // JSON-RPC calls (30s timeout)
sseClient *http.Client // SSE streaming (no timeout)
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
@ -134,7 +135,8 @@ func NewSignalChannel(cfg *config.Config, b *bus.MessageBus) (channels.Channel,
return &SignalChannel{
BaseChannel: base,
config: signalCfg,
httpClient: &http.Client{Timeout: signalRPCTimeout},
rpcClient: &http.Client{Timeout: signalRPCTimeout},
sseClient: &http.Client{Timeout: 0},
}, nil
}
@ -291,8 +293,7 @@ func (c *SignalChannel) connectSSE() error {
}
req.Header.Set("Accept", "text/event-stream")
sseClient := &http.Client{Timeout: 0}
resp, err := sseClient.Do(req)
resp, err := c.sseClient.Do(req)
if err != nil {
return fmt.Errorf("SSE connection failed: %w", err)
}
@ -659,7 +660,7 @@ func (c *SignalChannel) rpcCall(ctx context.Context, method string, params any)
}
httpReq.Header.Set("Content-Type", "application/json")
resp, err := c.httpClient.Do(httpReq)
resp, err := c.rpcClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("RPC request failed: %w", err)
}