-
Notifications
You must be signed in to change notification settings - Fork 328
fix: ensure bufferWriter returns an error when exceeding maxResponseBodyBytes #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,6 +164,19 @@ func (b *Buffer) ServeHTTP(w http.ResponseWriter, req *http.Request) { | |
|
|
||
| outReq := b.copyRequest(req, body, totalSize) | ||
|
|
||
| defer func() { | ||
| if err := recover(); err != nil { | ||
| if err == http.ErrAbortHandler { | ||
| b.log.Error("vulcand/oxy/buffer: failed to read response, err: %v", err) | ||
|
|
||
| b.errHandler.ServeHTTP(w, req, err.(error)) | ||
| return | ||
| } | ||
|
|
||
| panic(err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about that.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact that the After giving it some thought, I wonder if there might be impacts I didn't anticipate. Perhaps an approach like this (#247) might be safer. |
||
| } | ||
| }() | ||
|
|
||
| attempt := 1 | ||
| for { | ||
| // We create a special writer that will limit the response size, buffer it to disk if necessary | ||
|
|
@@ -292,14 +305,7 @@ func (b *bufferWriter) Header() http.Header { | |
| } | ||
|
|
||
| func (b *bufferWriter) Write(buf []byte) (int, error) { | ||
| length, err := b.buffer.Write(buf) | ||
| if err != nil { | ||
| // Since go1.11 (https://github.com/golang/go/commit/8f38f28222abccc505b9a1992deecfe3e2cb85de) | ||
| // if the writer returns an error, the reverse proxy panics | ||
| b.log.Error("write: %v", err) | ||
| length = len(buf) | ||
| } | ||
| return length, nil | ||
| return b.buffer.Write(buf) | ||
| } | ||
|
|
||
| // WriteHeader sets rw.Code. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with this recover, you will catch all the panic from other middleware.