Skip to content

Commit 0563b84

Browse files
committed
fix closeChan leak
1 parent 37ac814 commit 0563b84

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

client/transport/sse.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ func NewSSE(baseURL string, options ...ClientOption) (*SSE, error) {
5454
}
5555

5656
smc := &SSE{
57-
baseURL: parsedURL,
58-
httpClient: &http.Client{},
59-
responses: make(map[int64]chan *JSONRPCResponse),
60-
endpointChan: make(chan struct{}),
61-
headers: make(map[string]string),
57+
baseURL: parsedURL,
58+
httpClient: &http.Client{},
59+
responses: make(map[int64]chan *JSONRPCResponse),
60+
headers: make(map[string]string),
6261
}
6362

6463
for _, opt := range options {
@@ -104,6 +103,9 @@ func (c *SSE) Start(ctx context.Context) error {
104103
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
105104
}
106105

106+
c.endpointChan = make(chan struct{})
107+
defer close(c.endpointChan)
108+
107109
go c.readSSE(resp.Body)
108110

109111
// Wait for the endpoint to be received
@@ -184,7 +186,7 @@ func (c *SSE) handleSSEEvent(event, data string) {
184186
return
185187
}
186188
c.endpoint = endpoint
187-
close(c.endpointChan)
189+
c.endpointChan <- struct{}{}
188190

189191
case "message":
190192
var baseMessage JSONRPCResponse

0 commit comments

Comments
 (0)