size icon indicating copy to clipboard operation
size copied to clipboard

Careful: is not safe for concurrent use

Open Magomogo opened this issue 2 years ago • 3 comments

Not sure if client code should implement the right locking or this can be done in this package.

fatal error: concurrent map read and map write
goroutine 17031842 [running]:
runtime.throw(0xc0d666, 0x21)
         /usr/local/lib/go1.16.4/src/runtime/panic.go:1117 +0x72 fp=0xc1e27c97f0 sp=0xc1e27c97c0 pc=0x438af2
runtime.mapaccess2(0xb3a2a0, 0xc0295d74d0, 0xc16190f330, 0xc16190f330, 0x0)
         /usr/local/lib/go1.16.4/src/runtime/map.go:469 +0x255 fp=0xc1e27c9830 sp=0xc1e27c97f0 pc=0x411235
reflect.mapaccess(0xb3a2a0, 0xc0295d74d0, 0xc16190f330, 0xc04cbe)
         /usr/local/lib/go1.16.4/src/runtime/map.go:1318 +0x3f fp=0xc1e27c9868 sp=0xc1e27c9830 pc=0x4681ff
reflect.Value.MapIndex(0xb3a2a0, 0xc0295d74d0, 0x15, 0xb111a0, 0xc16190f330, 0x98, 0xb2c140, 0x10f4bd8, 0x99)
         /usr/local/lib/go1.16.4/src/reflect/value.go:1189 +0x16e fp=0xc1e27c98e0 sp=0xc1e27c9868 pc=0x4a6fce
github.com/DmitriyVTitov/size.sizeOf(0xb3a2a0, 0xc0295d74d0, 0x15, 0xc1e27c9a70, 0x18)
         /home/developer/go/pkg/mod/github.com/!dmitriy!v!titov/[email protected]/size.go:119 +0x915 fp=0xc1e27c99d8 sp=0xc1e27c98e0 pc=0xaab455
github.com/DmitriyVTitov/size.Of(0xb3a2a0, 0xc0295d74d0, 0x18)
         /home/developer/go/pkg/mod/github.com/!dmitriy!v!titov/[email protected]/size.go:18 +0x151 fp=0xc1e27c9ab0 sp=0xc1e27c99d8 pc=0xaaaab1

Magomogo avatar May 23 '22 09:05 Magomogo

This package is not (and cannot be as far as I know) a thread safe. So locking must be done in client code. I think this is the main reason why we don't have built-in tool for runtime memory consumption measurement.

DmitriyVTitov avatar May 23 '22 09:05 DmitriyVTitov

@Magomogo I am also experiencing the same issue. Were you bale to resolve it?

sonisidhant avatar Jan 10 '24 06:01 sonisidhant

@sonisidhant no, I'm not.

Magomogo avatar Jan 10 '24 12:01 Magomogo