Closed ezh closed 7 months ago
I can apply a workaround, but certainly, preemptively checking the connection status before each read would not be the most efficient or elegant solution.
Honestly, I'm quite surprised that huge corporations are using the code with such behavior in production. Thank you for the code, anyway.
I fail to see what is bothering you. What's your problem with io.ErrShortBuffer
?
io.ErrShortBuffer
indicates at the same time:
We expect to get 3 bytes.
conn.Read
returns io.ErrShortBuffer
because there is no data at allconn.Read
one more time, the client sends 1 byte, and we have io.ErrShortBuffer
againio.ErrShortBuffer
againDo you think the behavior is correct? If so, I'll close the report. š¤·āāļø
I understand that we can track the status with the event handler, or even write the custom state machine.
But my question is about conn.Read behavior.
gnet
is a event-driven framework, you should only read data in OnTraffic
, why would you call Read()
constantly to check if there is data coming? I don't think you're using gnet
in the right way.
Thank you for your quick feedback. I appreciate your guidance and will verify the usage to align with best practices.
Maybe I didn't get the idea.
Actions I've taken before I'm here
What happened?
https://github.com/panjf2000/gnet/blob/master/connection_unix.go#L306
A closed connection with an empty buffer(because of a lack of incoming data) returns a ShortBuffer error
NB. opened connection also returns a shortbuffer when there is no incoming data, but it is not so critical š .
Major version of gnet
v2
Specific version of gnet
v2.5.1
Operating system
macOS
OS version
Darwin 23.4.0 arm64
Go version
go version go1.22.2 darwin/arm64
Relevant log output
Code snippets (optional)
No response
How to Reproduce
create listener like
And connect with the TCP session.
Than, on an empty connection, do
it will return
io.ErrShortBuffer
close connection in a go routine
do
conn.Read
on more time on closed connection and š¤·āāļøDoes this issue reproduce with the latest release?
It can reproduce with the latest release