Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent map read and map write causing fatal error #197

Closed
hengyoush opened this issue Dec 19, 2024 · 1 comment · Fixed by #198
Closed

Concurrent map read and map write causing fatal error #197

hengyoush opened this issue Dec 19, 2024 · 1 comment · Fixed by #198
Assignees
Labels
bug Something isn't working

Comments

@hengyoush
Copy link
Owner

Describe the bug
Encountering a fatal error: concurrent map read and map write in the kyanos.

To Reproduce
Steps to reproduce the behavior:

./kyanos watch redis

Expected behavior
no panic

Screenshots/Log
panic.log

Information (please complete the following information):

  • OS: [e.g. use uname -ar]
@hengyoush hengyoush added the bug Something isn't working label Dec 19, 2024
@hengyoush hengyoush added this to v1.5.0 Dec 19, 2024
@hengyoush hengyoush moved this to In Progress in v1.5.0 Dec 19, 2024
@hengyoush hengyoush self-assigned this Dec 19, 2024
Copy link

dosubot bot commented Dec 19, 2024

To resolve the fatal error: concurrent map read and map write issue in kyanos, ensure that all access to shared data structures, such as maps, is properly synchronized. Use a sync.Mutex to protect access to these structures. For example, if you have a slice or map that is accessed by multiple goroutines, wrap the read and write operations with lock.Lock() and lock.Unlock() to prevent concurrent access.

Here's a snippet showing how to use a mutex to protect access to a shared slice:

func (m *model) updateRowsInTable() {
    lock.Lock()
    defer lock.Unlock()
    // operations on m.records
}

Similarly, ensure that any goroutine accessing shared data is also protected:

go func(mod *model, channel chan *common.AnnotatedRecord) {
    for {
        select {
        case <-ctx.Done():
            return
        case r := <-ch:
            lock.Lock()
            *m.records = append(*m.records, r)
            if len(*m.records) > m.options.MaxRecords {
                *m.records = (*m.records)[(len(*m.records) - m.options.MaxRecords):]
            }
            lock.Unlock()
        }
    }
}(m, ch)

Make sure every access to shared data is protected by the mutex to prevent concurrent read and write operations [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@hengyoush hengyoush linked a pull request Dec 19, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from In Progress to Done in v1.5.0 Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant