Skip to content

Commit 5af388d

Browse files
committed
Narrow the locking window when accessing v4AuthPair map
In this commit d6abc17 Fix race condition when updating v4AuthPair map 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. See: https://forum.rclone.org/t/can-rclone-serve-s3-handle-more-than-one-client/48329/
1 parent e89eb57 commit 5af388d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

gofakes3.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ type GoFakeS3 struct {
4141
log Logger
4242

4343
// simple v4 signature
44+
mu sync.RWMutex // protects vAuthPair map only
4445
v4AuthPair map[string]string
45-
mu sync.RWMutex
4646
}
4747

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

0 commit comments

Comments
 (0)