lnrpc: use request context in WebSocket proxy

The request context was not properly used to pass it along to the gRPC
endpoint which caused streaming calls to still be active on the gRPC
side even if the WS side already hung up.
We also issue an explicit close on the forwarding writer to signal when
the WS side was closed.
This commit is contained in:
Oliver Gugger
2021-07-22 15:43:12 +02:00
parent 29a8661517
commit 5f94ebbd7d

View File

@@ -147,12 +147,12 @@ func (p *WebsocketProxy) upgradeToWebSocketProxy(w http.ResponseWriter,
}
}()
ctx, cancelFn := context.WithCancel(context.Background())
ctx, cancelFn := context.WithCancel(r.Context())
defer cancelFn()
requestForwarder := newRequestForwardingReader()
request, err := http.NewRequestWithContext(
r.Context(), r.Method, r.URL.String(), requestForwarder,
ctx, r.Method, r.URL.String(), requestForwarder,
)
if err != nil {
p.logger.Errorf("WS: error preparing request:", err)
@@ -181,6 +181,7 @@ func (p *WebsocketProxy) upgradeToWebSocketProxy(w http.ResponseWriter,
go func() {
<-ctx.Done()
responseForwarder.Close()
requestForwarder.CloseWriter()
}()
go func() {