Skip to content

Commit

Permalink
use lock table on slurp to prevent double writing to the same key
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Nov 14, 2024
1 parent 42aba32 commit ed434c5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions zipserver/slurp_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"time"
)

var slurpLockTable = NewLockTable()

func slurpHandler(w http.ResponseWriter, r *http.Request) error {
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(globalConfig.JobTimeout))
defer cancel()
Expand All @@ -23,6 +25,11 @@ func slurpHandler(w http.ResponseWriter, r *http.Request) error {
return err
}

if !slurpLockTable.tryLockKey(key) {
return fmt.Errorf("Key is currently being processed: %s", key)
}
defer slurpLockTable.releaseKey(key)

slurpURL, err := getParam(params, "url")
if err != nil {
return err
Expand Down

0 comments on commit ed434c5

Please sign in to comment.