Skip to content

Conversation

@forrestIsRunning
Copy link
Contributor

Description

This PR fixes concurrent map access issues in the promptRegistry. The race conditions occur in two main scenarios:

  1. Background Polling vs Business Access

    • A background goroutine polls and updates the promptRegistry every 5 seconds (via pollPrompts)
    • Meanwhile, business logic reads the registry through GetOpenAIChatCompletionRequest
    • This creates a read/write race condition on the shared map
  2. Multiple Client Requests

    • Multiple API requests can trigger GetOpenAIChatCompletionRequest simultaneously
    • Each request reads from the promptRegistry
    • While these reads occur, the background polling might update the map

Changes

  • Added mutex lock protection in populatePromptRegistry() for map writes
  • Ensured proper read lock usage in getPromptVersion()
  • Protected all concurrent map access points with sync.RWMutex

Copy link
Member

@nirga nirga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@nirga nirga merged commit 2efc3a3 into traceloop:main Mar 13, 2025
4 checks passed
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