Skip to content
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

Ensure Request Body Readers are closed in LFS server #8454

Merged
merged 2 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions modules/lfs/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ func PostLockHandler(ctx *context.Context) {
}

var req api.LFSLockRequest
dec := json.NewDecoder(ctx.Req.Body().ReadCloser())
bodyReader := ctx.Req.Body().ReadCloser()
defer bodyReader.Close()
dec := json.NewDecoder(bodyReader)
if err := dec.Decode(&req); err != nil {
writeStatus(ctx, 400)
return
Expand Down Expand Up @@ -269,7 +271,9 @@ func UnLockHandler(ctx *context.Context) {
}

var req api.LFSLockDeleteRequest
dec := json.NewDecoder(ctx.Req.Body().ReadCloser())
bodyReader := ctx.Req.Body().ReadCloser()
defer bodyReader.Close()
dec := json.NewDecoder(bodyReader)
if err := dec.Decode(&req); err != nil {
writeStatus(ctx, 400)
return
Expand Down
12 changes: 9 additions & 3 deletions modules/lfs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ func PutHandler(ctx *context.Context) {
}

contentStore := &ContentStore{BasePath: setting.LFS.ContentPath}
if err := contentStore.Put(meta, ctx.Req.Body().ReadCloser()); err != nil {
bodyReader := ctx.Req.Body().ReadCloser()
defer bodyReader.Close()
if err := contentStore.Put(meta, bodyReader); err != nil {
ctx.Resp.WriteHeader(500)
fmt.Fprintf(ctx.Resp, `{"message":"%s"}`, err)
if err = repository.RemoveLFSMetaObjectByOid(rv.Oid); err != nil {
Expand Down Expand Up @@ -434,7 +436,9 @@ func unpack(ctx *context.Context) *RequestVars {

if r.Method == "POST" { // Maybe also check if +json
var p RequestVars
dec := json.NewDecoder(r.Body().ReadCloser())
bodyReader := r.Body().ReadCloser()
defer bodyReader.Close()
dec := json.NewDecoder(bodyReader)
err := dec.Decode(&p)
if err != nil {
return rv
Expand All @@ -453,7 +457,9 @@ func unpackbatch(ctx *context.Context) *BatchVars {
r := ctx.Req
var bv BatchVars

dec := json.NewDecoder(r.Body().ReadCloser())
bodyReader := r.Body().ReadCloser()
defer bodyReader.Close()
dec := json.NewDecoder(bodyReader)
err := dec.Decode(&bv)
if err != nil {
return &bv
Expand Down