• Kirill Smelkov's avatar
    wcfs: Fix setupWatch vs setupWatch race on the same file · 2fe57e8d
    Kirill Smelkov authored
    WCFS allows issuing simultaneous watch requests and when two watch
    requests are simultaneously issued for the same file there was a race in
    their handling: the code was relying on w.atMu.W to protect setupWatch
    from concurrent readPinWatcher, and also, seemingly from another
    setupWatch running on the same file.
    
    But there is a bug about that: lacking atomic primitive to downgrade
    RWMutex from wlock to rlock, atMu.W was first fully unlocked and then
    rlocked again. The code prepare wrt readPinWatcher to start running in
    that unlock->rlock time window, but it was not prepared wrt another
    setupWatch starting to run on the same file in that pause time.
    
    -> Fix that via using dedicated Watch.setupMu lock that protects
       setupWatch from setupWatch.
    
    Test is, hopefully, TODO.
    
    My mistake from 6f0cdaff (wcfs: Provide isolation to clients)
    2fe57e8d
wcfs.go 81.5 KB