Skip to content

Commit

Permalink
fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur committed Oct 14, 2024
1 parent ed703a4 commit 5d5c3b2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/block/upload_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (uh *UploadHandler) statusNotifier(bytesUploaded int64) {

// Upload next chunk if available.
if uh.chunks.Len() > 0 {
if uh.chunks.Len() == 1 && uh.status == ReadyToFinalize {
_ = uh.uploadFinalChunk()
return
}
err := uh.uploadChunk()
if err != nil {
return
Expand Down Expand Up @@ -174,6 +178,29 @@ func (uh *UploadHandler) uploadChunk() error {
return nil
}

func (uh *UploadHandler) uploadFinalChunk() (err error) {
listEle := uh.chunks.Front()
if listEle == nil {
logger.Errorf("Got empty list in upload chunk")
}
uh.bufferInProgress = listEle.Value.(Block)
uh.chunks.Remove(listEle)

go func() {
err = uh.bucket.Upload(uh.writer, uh.bufferInProgress)
if err != nil {
logger.Warnf("Upload failed: %v", err)
uh.status = Failed
return
}
err = uh.Finalize()
if err != nil {
return
}
}()
return nil
}

func (uh *UploadHandler) Finalize() error {
// Notstarted
// Empty file, createobject on GCS
Expand Down

0 comments on commit 5d5c3b2

Please sign in to comment.