Use a sync.Once in Conn.Close
@@ -33,6 +33,7 @@ type Conn struct {
currDataMut sync.RWMutex
currData bytes.Buffer
closeOnce sync.Once
+ closeSignalOnce sync.Once
closeSignal chan struct{}
dataSignal chan struct{}
localAddr net.Addr
@@ -126,14 +127,16 @@ func (c *Conn) Write(b []byte) (n int, err error) {
// close error, subsequent and concurrent calls will return nil.
// This method is thread-safe.
func (c *Conn) Close() error {
+ c.closeOnce.Do(func() {
c.signalClose()
c.Call("close")
c.releaseHandlers()
+ })
return nil
}
func (c *Conn) signalClose() {
- c.closeOnce.Do(func() {
+ c.closeSignalOnce.Do(func() {
close(c.closeSignal)
})
}
