Skip to content

Commit

Permalink
Narrow the locking window when accessing v4AuthPair map
Browse files Browse the repository at this point in the history
In this commit

d6abc17 Fix race condition when updating v4AuthPair map

See: https://forum.rclone.org/t/can-rclone-serve-s3-handle-more-than-one-client/48329/
We put in locking to access the v4AuthPair map. However this locking
extended over the HTTP request which means that it effectively made
the server single threaded in certain cases.

This fix narrows the locking window to fix the problem.
  • Loading branch information
ncw committed Oct 24, 2024
1 parent e89eb57 commit f3a2bf7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gofakes3.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type GoFakeS3 struct {
log Logger

// simple v4 signature
mu sync.RWMutex // protects vAuthPair map only
v4AuthPair map[string]string
mu sync.RWMutex
}

// New creates a new GoFakeS3 using the supplied Backend. Backends are pluggable.
Expand Down Expand Up @@ -120,8 +120,9 @@ func (g *GoFakeS3) DelAuthKeys(p []string) {
func (g *GoFakeS3) authMiddleware(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, rq *http.Request) {
g.mu.RLock()
defer g.mu.RUnlock()
if len(g.v4AuthPair) > 0 {
haveAuth := len(g.v4AuthPair) > 0
g.mu.RUnlock()
if haveAuth {
if result := signature.V4SignVerify(rq); result != signature.ErrNone {
g.log.Print(LogWarn, "Access Denied:", rq.RemoteAddr, "=>", rq.URL)

Expand Down

0 comments on commit f3a2bf7

Please sign in to comment.