Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite29a179

Browse files
committed
Unlock in defer
1 parent5562335 commite29a179

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

‎pkg/lockdown/lockdown.go‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,31 +102,28 @@ func (c *RepoAccessCache) GetRepoAccessInfo(ctx context.Context, username, owner
102102
key:=cacheKey(owner,repo)
103103
userKey:=strings.ToLower(username)
104104
c.mu.Lock()
105+
deferc.mu.Unlock()
105106
entry:=c.ensureEntry(key)
106107
ifentry.ready {
107108
ifcachedHasPush,known:=entry.knownUsers[userKey];known {
108109
entry.scheduleExpiry(c,key)
109110
c.logDebug("repo access cache hit","owner",owner,"repo",repo,"user",username)
110111
cachedPrivate:=entry.isPrivate
111-
c.mu.Unlock()
112112
returncachedPrivate,cachedHasPush,nil
113113
}
114114
}
115-
c.mu.Unlock()
116115
c.logDebug("repo access cache miss","owner",owner,"repo",repo,"user",username)
117116

118117
isPrivate,hasPush,err:=c.queryRepoAccessInfo(ctx,username,owner,repo)
119118
iferr!=nil {
120119
returnfalse,false,err
121120
}
122121

123-
c.mu.Lock()
124122
entry=c.ensureEntry(key)
125123
entry.ready=true
126124
entry.isPrivate=isPrivate
127125
entry.knownUsers[userKey]=hasPush
128126
entry.scheduleExpiry(c,key)
129-
c.mu.Unlock()
130127

131128
returnisPrivate,hasPush,nil
132129
}

‎pkg/lockdown/lockdown_test.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ func requireAccess(ctx context.Context, t *testing.T, cache *RepoAccessCache) {
9898

9999
funcTestRepoAccessCacheEvictsAfterTTL(t*testing.T) {
100100
t.Parallel()
101+
ctx:=t.Context()
101102

102103
cache,transport:=newMockRepoAccessCache(t,5*time.Millisecond)
103-
ctx:=context.Background()
104-
105104
requireAccess(ctx,t,cache)
106105
requireAccess(ctx,t,cache)
107106
require.EqualValues(t,1,transport.CallCount())
@@ -113,10 +112,10 @@ func TestRepoAccessCacheEvictsAfterTTL(t *testing.T) {
113112
}
114113

115114
funcTestRepoAccessCacheTTLDisabled(t*testing.T) {
115+
ctx:=t.Context()
116116
t.Parallel()
117117

118118
cache,transport:=newMockRepoAccessCache(t,0)
119-
ctx:=context.Background()
120119

121120
requireAccess(ctx,t,cache)
122121
requireAccess(ctx,t,cache)
@@ -129,10 +128,10 @@ func TestRepoAccessCacheTTLDisabled(t *testing.T) {
129128
}
130129

131130
funcTestRepoAccessCacheSetTTLReschedulesExistingEntry(t*testing.T) {
131+
ctx:=t.Context()
132132
t.Parallel()
133133

134134
cache,transport:=newMockRepoAccessCache(t,0)
135-
ctx:=context.Background()
136135

137136
requireAccess(ctx,t,cache)
138137
require.EqualValues(t,1,transport.CallCount())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp