One thing strikes me with the locking code: This patch touches on a lot of critical sections, but the pattern of how you are locking and unlocking is not consistent and hence we might run into bugs in the future. For example, in this section you are using `defer`, but in other parts you are handling this manually:

```
s.closeMu.Lock()
if s.isClosed {
    s.closeMu.Unlock()
    return
}
s.isClosed = true
s.closeMu.Unlock()
```