Skip to content

Commit 766cc32

Browse files
committed
Fix concurrent map write
The previous fix didn't address the issue after all, as the caches were passed by value. The map was still shared, being a reference type, but the mutex was being copied, rendering it useless.
1 parent ec7a725 commit 766cc32

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1010

1111
### Changed
1212

13-
- aucoalesce - Made the user/group ID cache thread-safe. #42
13+
- aucoalesce - Made the user/group ID cache thread-safe. #42 #45
1414

1515
### Deprecated
1616

aucoalesce/id_lookup.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ type UserCache struct {
4848
mutex sync.Mutex
4949
}
5050

51-
// NewUserCache returns a new UserCache. UserCache is not thread-safe.
52-
func NewUserCache(expiration time.Duration) UserCache {
53-
return UserCache{
51+
// NewUserCache returns a new UserCache. UserCache is thread-safe.
52+
func NewUserCache(expiration time.Duration) *UserCache {
53+
return &UserCache{
5454
expiration: expiration,
5555
data: map[string]stringItem{
5656
"0": {timeout: time.Unix(math.MaxInt64, 0), value: "root"},
@@ -91,9 +91,9 @@ type GroupCache struct {
9191
mutex sync.Mutex
9292
}
9393

94-
// NewGroupCache returns a new GroupCache. GroupCache is not thread-safe.
95-
func NewGroupCache(expiration time.Duration) GroupCache {
96-
return GroupCache{
94+
// NewGroupCache returns a new GroupCache. GroupCache is thread-safe.
95+
func NewGroupCache(expiration time.Duration) *GroupCache {
96+
return &GroupCache{
9797
expiration: expiration,
9898
data: map[string]stringItem{
9999
"0": {timeout: time.Unix(math.MaxInt64, 0), value: "root"},
@@ -136,7 +136,7 @@ func ResolveIDs(event *Event) {
136136

137137
// ResolveIDsFromCaches translates all uid and gid values to their associated
138138
// names using the provided caches. Prior to Go 1.9 this requires cgo on Linux.
139-
func ResolveIDsFromCaches(event *Event, users UserCache, groups GroupCache) {
139+
func ResolveIDsFromCaches(event *Event, users *UserCache, groups *GroupCache) {
140140
// Actor
141141
if v := users.LookupUID(event.Summary.Actor.Primary); v != "" {
142142
event.Summary.Actor.Primary = v

0 commit comments

Comments
 (0)