Skip to content

Commit

Permalink
fix: handle resumeFile close and reduce autosave num
Browse files Browse the repository at this point in the history
  • Loading branch information
crebsy committed Jul 12, 2024
1 parent 11fa4ef commit 9c4ec7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,6 @@ func downloadoor(index *moonproto.Index, resumeCtx *ResumeCtx, chunkChan chan<-
}

retry:
if localLength == 0 {
continue
}
// get url for lib
libUrlCreds, err := getSnapUrlCreds(libName)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ResumeCtx struct {

const RANGE_BITSET_SIZE = 1024 * 1024 / 8

const AUTOSAVE_AFTER_N_CHUNKS = 8192
const AUTOSAVE_AFTER_N_CHUNKS = 128

func (b Bitset) Set(idx int) {
b[idx/8] |= 1 << (idx % 8)
Expand Down Expand Up @@ -171,6 +171,10 @@ func (r *ResumeCtx) persist() {
r.lock.Lock()
defer r.lock.Unlock()

if r.resumeFile == nil {
return
}

offset, err := r.resumeFile.Seek(0, io.SeekCurrent)
if err != nil {
panic(err)
Expand Down Expand Up @@ -218,8 +222,11 @@ func (r *ResumeCtx) persist() {
func (r *ResumeCtx) close() {
r.persist()

r.lock.Lock()
err := r.resumeFile.Close()
if err != nil {
panic(err)
}
r.resumeFile = nil
r.lock.Unlock()
}

0 comments on commit 9c4ec7d

Please sign in to comment.