Skip to content

Commit 5c66ef0

Browse files
authored
Merge pull request #367 from kmala/bug
fix(sshd): unlock the repository when gitreceive succeeds or fails
2 parents 5a5371c + 96ebdfa commit 5c66ef0

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

pkg/sshd/lock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ func wrapInLock(lck RepositoryLock, repoName string, fn func() error) error {
3838
case <-doneCh:
3939
}
4040
}()
41+
defer lck.Unlock(repoName)
4142
select {
4243
case <-timer.C:
43-
lck.Unlock(repoName)
4444
defer close(doneCh)
4545
return fmt.Errorf("%s lock exceeded timout", repoName)
4646
case err := <-fnCh:

pkg/sshd/lock_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sshd
22

33
import (
4+
"errors"
45
"sync"
56
"testing"
67
"time"
@@ -12,6 +13,10 @@ const (
1213
callbackTimeout = 1 * time.Second
1314
)
1415

16+
var (
17+
gitError = errors.New("git receive error")
18+
)
19+
1520
func TestMultipleSameRepoLocks(t *testing.T) {
1621
var wg sync.WaitGroup
1722
const repo = "repo1"
@@ -91,7 +96,10 @@ func TestWrapInLock(t *testing.T) {
9196
assert.NoErr(t, wrapInLock(lck, "repo", func() error {
9297
return nil
9398
}))
94-
lck.Lock("repo")
99+
assert.Err(t, gitError, wrapInLock(lck, "repo", func() error {
100+
return gitError
101+
}))
102+
assert.NoErr(t, lck.Lock("repo"))
95103
assert.Err(t, errAlreadyLocked, wrapInLock(lck, "repo", func() error {
96104
return nil
97105
}))

0 commit comments

Comments
 (0)