Fix some more races

This commit is contained in:
2023-03-10 00:07:29 +10:30
parent f2c05d0144
commit 3e7a3a2f3b
2 changed files with 21 additions and 3 deletions

11
main.go
View File

@@ -327,7 +327,11 @@ func fetchInfoOneRESTHandler(w http.ResponseWriter, r *http.Request) {
}
// just a get, return the object
thisDownload.Lock.Lock()
defer thisDownload.Lock.Unlock()
b, _ := json.Marshal(thisDownload)
w.Write(b)
return
} else {
@@ -337,9 +341,10 @@ func fetchInfoOneRESTHandler(w http.ResponseWriter, r *http.Request) {
func fetchInfoRESTHandler(w http.ResponseWriter, r *http.Request) {
dm.Lock.Lock()
defer dm.Lock.Unlock()
b, _ := json.Marshal(dm.Downloads)
b, err := dm.DownloadsAsJSON()
if err != nil {
panic(err)
}
w.Write(b)
}