Closed elliotcourant closed 2 years ago
Looks good. You can also do something like this:
ln.mu.Lock()
ln.channels = removeIfExists(ln.channels, channels...)
cn, err := ln.conn(ctx)
ln.mu.Unlock()
I think this is a cleaner change, I’ll make that adjustment today On Oct 4, 2022 at 6:24 AM -0500, Vladimir Mihailenco @.***>, wrote:
Looks good. You can also do something like this: ln.mu.Lock() ln.channels = removeIfExists(ln.channels, channels...) cn, err := ln.conn(ctx) ln.mu.Unlock() — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
This resolves a race condition in listener where
ln.closed
was being read without a mutex at the same time it could be written. Just move the mutex unlock forUnlisten
down, but not defer it so that the mutex still holds the lock properly. But does not cause a deadlock with release conn.