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:
parent
b5bd7985c6
commit
af25536c19
1 changed files with 10 additions and 9 deletions
|
|
@ -39,11 +39,12 @@ const (
|
|||
// Implements: channels.Channel, channels.TypingCapable, channels.ReactionCapable
|
||||
type SignalChannel struct {
|
||||
*channels.BaseChannel
|
||||
config config.SignalConfig
|
||||
httpClient *http.Client
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
wg sync.WaitGroup
|
||||
config config.SignalConfig
|
||||
rpcClient *http.Client // JSON-RPC calls (30s timeout)
|
||||
sseClient *http.Client // SSE streaming (no timeout)
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
// Signal SSE event types
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue