• Kirill Smelkov's avatar
    X zodb/cache: A concurency bug was found · 42687746
    Kirill Smelkov authored
    which is showing itself as e.g.
    
    ---- 8< ----
    panic: Buf: refcnt < 0
    
    goroutine 7 [running]:
    lab.nexedi.com/kirr/neo/go/zodb.(*Buf).Release(0xc42000db40)
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/buffer.go:107 +0x116
    lab.nexedi.com/kirr/neo/go/zodb.(*Buf).XRelease(0xc42000db40)
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/buffer.go:136 +0x3a
    lab.nexedi.com/kirr/neo/go/zodb.(*Cache).gc(0xc4200101c0)
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/cache.go:488 +0x22f
    lab.nexedi.com/kirr/neo/go/zodb.(*Cache).gcmain(0xc4200101c0)
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/cache.go:451 +0x3f
    created by lab.nexedi.com/kirr/neo/go/zodb.NewCache
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/cache.go:123 +0x126
    ---- 8< ----
    
    during zhash.go -prefetch run.
    
    This patch adds the test for this bug and explains the problem in detail
    there. The test currently fails:
    
    --- FAIL: TestCache (0.01s)
    panic: Buf.Incref: refcnt was < 1 [recovered]
            panic: Buf.Incref: refcnt was < 1
    
    goroutine 18 [running]:
    testing.tRunner.func1(0xc4240ce000)
            /home/kirr/src/tools/go/go/src/testing/testing.go:711 +0x2d2
    panic(0x588a20, 0x5ebe70)
            /home/kirr/src/tools/go/go/src/runtime/panic.go:491 +0x283
    lab.nexedi.com/kirr/neo/go/zodb.(*Buf).Incref(0xc4200c2460)
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/buffer.go:134 +0x58
    lab.nexedi.com/kirr/neo/go/zodb.(*Buf).XIncref(0xc4200c2460)
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/buffer.go:148 +0x3a
    lab.nexedi.com/kirr/neo/go/zodb.(*Cache).Load(0xc4200ca000, 0x6ab1a0, 0xc42001a148, 0x4, 0x1, 0x10, 0xc4200bf2e0, 0x10, 0x10)
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/cache.go:168 +0x1c7
    lab.nexedi.com/kirr/neo/go/zodb.TestCache.func2(0x4, 0x1, 0xc4200c2440, 0x4, 0x0, 0x0)
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/cache_test.go:155 +0xcc
    lab.nexedi.com/kirr/neo/go/zodb.TestCache(0xc4240ce000)
            /home/kirr/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/cache_test.go:579 +0x4eb5
    testing.tRunner(0xc4240ce000, 0x5d4728)
            /home/kirr/src/tools/go/go/src/testing/testing.go:746 +0xd0
    created by testing.(*T).Run
            /home/kirr/src/tools/go/go/src/testing/testing.go:789 +0x2de
    exit status 2
    42687746
cache.go 15.8 KB