-
-
Couldn't load subscription status.
- Fork 2.3k
Closed
Description
While reviewing the proxy middleware code, I noticed that the proxy connection is not explicitly closed:
Lines 156 to 182 in e644ff8
| out, err := dialFunc(c.Request().Context(), "tcp", t.URL.Host) | |
| if err != nil { | |
| c.Set("_error", echo.NewHTTPError(http.StatusBadGateway, fmt.Sprintf("proxy raw, dial error=%v, url=%s", err, t.URL))) | |
| return | |
| } | |
| // Write header | |
| err = r.Write(out) | |
| if err != nil { | |
| c.Set("_error", echo.NewHTTPError(http.StatusBadGateway, fmt.Sprintf("proxy raw, request header copy error=%v, url=%s", err, t.URL))) | |
| return | |
| } | |
| errCh := make(chan error, 2) | |
| cp := func(dst io.Writer, src io.Reader) { | |
| _, err = io.Copy(dst, src) | |
| errCh <- err | |
| } | |
| go cp(out, in) | |
| go cp(in, out) | |
| err = <-errCh | |
| if err != nil && err != io.EOF { | |
| c.Set("_error", fmt.Errorf("proxy raw, copy body error=%w, url=%s", err, t.URL)) | |
| } | |
| }) | |
| } |
In practice, this may not immediately cause issues—the runtime’s finalizer will eventually close orphaned file descriptors—but it’s generally not safe to rely on this behavior.
Let me know if you’d like me to submit a PR with a fix.
Metadata
Metadata
Assignees
Labels
No labels