-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hello, I recently ran into an issue where there is a panic writing to a closed channel here.
I was able to create a quick test to reproduce this:
func TestSetAfterCloseNoPanic(t *testing.T) {
c, err := newTestCache()
require.NoError(t, err)
require.NotNil(t, c)
go c.Set(1, 1, 1)
go c.Close()
time.Sleep(time.Millisecond * 100)
}
On my side I'm working around this issue by just coordinating my go routines better here so that I wait for all my possible "Set" calls to complete before calling Close. So if anyone else runs into this, that's the easy way to get around it currently.
It seems like this is unintentional as there's a check here if the cache has been closed, however if the calls are concurrent it's possible for them to be ordered such that:
- The Set() call begins and verifies the Cache has not been closed
- Close() is called and the setBuf channel is closed
- Set() attempts to write to
setBuftriggering a panic
If this is considered incorrect usage of the library API feel free to close this issue, although I might recommend a small docs note on Close indicating that it must not be called concurrently with Set