Skip to content

fix: make LRUCache thread safe#26

Draft
honzap wants to merge 1 commit into
launchdarkly:v3from
honzap:honzap/fix/lrucachesync
Draft

fix: make LRUCache thread safe#26
honzap wants to merge 1 commit into
launchdarkly:v3from
honzap:honzap/fix/lrucachesync

Conversation

@honzap

@honzap honzap commented Mar 3, 2025

Copy link
Copy Markdown

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Describe the solution you've provided

We put LD libraries under the heavy load in production (>500M requests/24h) and the LRU cache starts panics, because it's not thread safe.

We're using the older version of library but the same code is there since a while.

Stack trace (at the bottom, there is a line 32 of lru_cache.go which produces a problem)

/go/pkg/mod/gopkg.in/launchdarkly/go-sdk-events.v1@v1.1.1/event_processor.go:145 +0x616
created by gopkg.in/launchdarkly/go-sdk-events%2ev1.startEventDispatcher in goroutine 525
/go/pkg/mod/gopkg.in/launchdarkly/go-sdk-events.v1@v1.1.1/event_processor.go:193 +0x4c9
gopkg.in/launchdarkly/go-sdk-events%2ev1.(*eventDispatcher).runMainLoop(0xc000b585a0, 0xc000ee8a80)
/go/pkg/mod/gopkg.in/launchdarkly/go-sdk-events.v1@v1.1.1/event_processor.go:263 +0x4ff
gopkg.in/launchdarkly/go-sdk-events%2ev1.(*eventDispatcher).processEvent(0xc000b585a0, {0x49834c0, 0xc0013bf408})
/go/pkg/mod/gopkg.in/launchdarkly/go-sdk-events.v1@v1.1.1/lru_cache.go:32 +0x45
gopkg.in/launchdarkly/go-sdk-events%2ev1.(*lruCache).add(0xc000b58728, {0x37e48a0, 0xc008de97f0})
goroutine 543 [running]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x476efd]
panic: runtime error: invalid memory address or nil pointer dereference

We think, there should be a RWMutex around that to avoid accessing invalid memory.

Describe alternatives you've considered

No other options.

Additional context

@honzap honzap requested a review from a team as a code owner March 3, 2025 16:17
@honzap honzap marked this pull request as draft March 3, 2025 16:28
@louis-launchdarkly

Copy link
Copy Markdown
Contributor

Hello @honzap, I saw @keelerm84 already replied to you in the GitHub issue, and he can help in looking at this contribution.

Filed Internally as SDK-1099

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants