go-socket.io icon indicating copy to clipboard operation
go-socket.io copied to clipboard

Why use sync.RWMutex in connection handle?

Open HelloFy opened this issue 6 years ago • 2 comments
trafficstars

type session struct {
	params    base.ConnParameters
	manager   *manager
	closeOnce sync.Once
	context   interface{}

	upgradeLocker sync.RWMutex
	transport     string
	conn          base.Conn
}

HelloFy avatar Aug 14 '19 08:08 HelloFy

I used conn.Emit("xx", "123") but this hang at the

func (w *writer) Write(p []byte) (int, error) {
	w.locker.Lock()
	defer w.locker.Unlock()
	return w.WriteCloser.Write(p)
}

but when i next call the conn.Emit(), the last emit result will flush to the client, and this emit still hang at the lock。

I remove the lock code, this will be run fine

HelloFy avatar Aug 14 '19 08:08 HelloFy

@HelloFy Hi Please send some more example code. If you want change some code, send new PR

sshaplygin avatar Oct 04 '19 11:10 sshaplygin