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

Commitb217a15

Browse files
committed
keyring tests: data races eliminated
1 parent1a96091 commitb217a15

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎internal/keyring/threadkeyring.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ func NewThreadKeyring(ctx context.Context, keyring *Keyring) (*ThreadKeyring, er
6969
tk.removekey=make(chan*removekeyMsg)
7070
tk.readkey=make(chan*readkeyMsg)
7171

72+
// Channel for initialization to prevent Data Race
73+
errCh:=make(chanerror,1)
74+
7275
tk.wg.Add(1)
7376
gofunc() {
7477
varak*Keyring
7578
runtime.LockOSThread()
7679
ak,err=keyring.CreateKeyring()
7780
iferr!=nil {
81+
errCh<-err
7882
return
7983
}
84+
errCh<-nil
8085
for {
8186
select {
8287
casemsg:=<-tk.addkey:
@@ -91,5 +96,11 @@ func NewThreadKeyring(ctx context.Context, keyring *Keyring) (*ThreadKeyring, er
9196
}
9297
}
9398
}()
99+
100+
// Wait for initialization to complete
101+
iferr:=<-errCh;err!=nil {
102+
returnnil,err
103+
}
104+
94105
return&tk,err
95106
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp