GithubHelp home page GithubHelp logo

Data race? about golang-fifo HOT 4 CLOSED

richardartoul avatar richardartoul commented on July 30, 2024
Data race?

from golang-fifo.

Comments (4)

richardartoul avatar richardartoul commented on July 30, 2024 1

Your hot fix looks good to me, but I don’t understand the two points you made above. The issue is just that there are two concurrent goroutines loading the same cache value at the same time and they both end up modifying the visited field because they’re not holding an exclusive lock.

another alternative would be to add a sub-lock inside the entry struct and acquire that before marking visited as true. For now though I’d probably merge your existing hot fix since the more complex solutions probably require detailed concurrent benchmarking.

from golang-fifo.

richardartoul avatar richardartoul commented on July 30, 2024

I could see this being an intentional performance thing if setting a boolean field compiles down to a single instruction 🤔 but it makes using this library in any codebase that runs tests with the race detector enabled impossible

from golang-fifo.

scalalang2 avatar scalalang2 commented on July 30, 2024

@richardartoul Thank you for reporting.

I've researched one thing that can cause this.

  1. Go map is not addressable which means the pointed value may change during performing operations
  2. Changes in pointed value can occur when go map rebalances itself to ensure O(1) access.

I think that there are two possible solutions here

  • Simply change RLock to Lock to make all operations work sequentially
  • Adopt a concurrent-map implementation like this or sync.Map

Hot Fixes

This is a critical bug, I'll handle it with a hotfix and conduct further researchs for this.

from golang-fifo.

scalalang2 avatar scalalang2 commented on July 30, 2024

I also want to hear @richardartoul opinions about this.

from golang-fifo.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.