Commit 692f1705 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'jv-fix-uploader-race' into 'master'

Fix objectstore.uploader.uploadError race

See merge request gitlab-org/gitlab-workhorse!583
parents aa34b2ac a3c000b9
---
title: Fix objectstore.uploader.uploadError race
merge_request: 583
author:
type: fixed
...@@ -100,9 +100,13 @@ func (u *uploader) Execute(ctx context.Context, deadline time.Time) { ...@@ -100,9 +100,13 @@ func (u *uploader) Execute(ctx context.Context, deadline time.Time) {
if u.metrics { if u.metrics {
go u.trackUploadTime() go u.trackUploadTime()
} }
go u.cleanup(ctx)
uploadDone := make(chan struct{})
go u.cleanup(ctx, uploadDone)
go func() { go func() {
defer cancelFn() defer cancelFn()
defer close(uploadDone)
if u.metrics { if u.metrics {
defer objectStorageUploadsOpen.Dec() defer objectStorageUploadsOpen.Dec()
} }
...@@ -145,10 +149,11 @@ func (u *uploader) trackUploadTime() { ...@@ -145,10 +149,11 @@ func (u *uploader) trackUploadTime() {
} }
} }
func (u *uploader) cleanup(ctx context.Context) { func (u *uploader) cleanup(ctx context.Context, uploadDone chan struct{}) {
// wait for the upload to finish // wait for the upload to finish
<-u.ctx.Done() <-u.ctx.Done()
<-uploadDone
if u.uploadError != nil { if u.uploadError != nil {
if u.metrics { if u.metrics {
objectStorageUploadRequestsRequestFailed.Inc() objectStorageUploadRequestsRequestFailed.Inc()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment