Skip to content

Commit 9b83225

Browse files
smothikiAaron Schlesinger
authored andcommitted
feat(lock): change cleaner lock from mutex to RWmutex
1 parent 9fa4d02 commit 9b83225

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

pkg/cleaner/cleaner.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ const (
2121
)
2222

2323
type Ref struct {
24-
mut *sync.Mutex
24+
mut *sync.RWMutex
2525
}
2626

2727
func NewRef() Ref {
28-
return Ref{mut: new(sync.Mutex)}
28+
return Ref{mut: new(sync.RWMutex)}
29+
}
30+
31+
func (c Ref) RLock() {
32+
c.mut.RLock()
33+
}
34+
35+
func (c Ref) RUnlock() {
36+
c.mut.RUnlock()
2937
}
3038

3139
func (c Ref) Lock() {

pkg/sshd/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (s *server) answer(channel ssh.Channel, requests <-chan *ssh.Request, sshCo
232232
}
233233

234234
repoName := parts[1]
235-
s.cleanerRef.Lock()
235+
s.cleanerRef.RLock()
236236
if err := s.pushLock.Lock(repoName, time.Duration(0)); err != nil {
237237
log.Errf(s.c, multiplePush)
238238
// The error must be in git format
@@ -241,7 +241,7 @@ func (s *server) answer(channel ssh.Channel, requests <-chan *ssh.Request, sshCo
241241
}
242242
sendExitStatus(1, channel)
243243
req.Reply(false, nil)
244-
s.cleanerRef.Unlock()
244+
s.cleanerRef.RUnlock()
245245
return nil
246246
}
247247

@@ -258,7 +258,7 @@ func (s *server) answer(channel ssh.Channel, requests <-chan *ssh.Request, sshCo
258258
// TODO: this is an important error case that needs to be covered
259259
// Probably the best solution is to change the lock into a lease so that even on unlock failures, RepositoryLock will eventually yield
260260
}
261-
s.cleanerRef.Unlock()
261+
s.cleanerRef.RUnlock()
262262
var xs uint32
263263
if err != nil {
264264
log.Errf(s.c, "Failed git receive: %v", err)

0 commit comments

Comments
 (0)