kataras / neffos

A modern, fast and scalable websocket framework with elegant API written in Go
http://bit.ly/neffos-wiki
MIT License
572 stars 47 forks source link

[BUG]when client send msg to server concurrently. how the server guarantee the response of ask(ctx, msg, mustWaitOnlyTheNextMessage) is matchs the send? #113

Open DOLLook opened 2 months ago

DOLLook commented 2 months ago

The ask in conn.go line 941. when server send msg to the client. it start a goroutine and runs c.Socket().ReadData(c.readTimeout) to read the next msg. But how it guarantee the next msg is the response that the ask method send? On the other hand, when websocket connected, the server runs startReader() that runs c.Socket().ReadData(c.readTimeout) in loop. In multi goroutine that may be run at the same time. Is it safe to read and how to guarantee the ask() method's response is matchs the ask()?

DOLLook commented 2 months ago

May be there is no need to use the param mustWaitOnlyTheNextMessage in ask() method. then the ask() method will always use the main loop to read response for the ask() and send the response by channel. finally the ask() can received the response synchronized.