Skip to content

Race issue #193

@gnurizen

Description

@gnurizen

On branch of our fork (gpu-fixes branch) need to see if still possible on upstream/main.

`
Data Race Summary

Writer (goroutine 123) - assignInterpreter() at line 242:
pm.interpreters[pid][key] = instance

Reader (goroutine 134) - MaybeNotifyAPMAgent() at lines 310-317:
pidInterp, ok := pm.interpreters[rawTrace.PID]
pm.mu.RUnlock() // Lock released here!
...
for _, mapping := range pidInterp { // Iterating without lock

The Bug:

  1. MaybeNotifyAPMAgent gets a reference to the inner map pm.interpreters[pid] while holding RLock
  2. It then releases the lock at line 311
  3. It then iterates over pidInterp at line 317 without any lock
  4. Meanwhile, assignInterpreter writes to that same inner map

The inner map is a reference type, so pidInterp points to the same underlying map that assignInterpreter is modifying. Releasing the lock before iterating creates the race window.

Fix options:

  1. Hold the RLock during the entire iteration (may cause lock contention)
  2. Copy the map values into a slice before releasing the lock
  3. Use a different synchronization strategy for the inner map
    `

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions