-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Read returns io.ErrShortBuffer on closed connection #598
Comments
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 |
We expect to get 3 bytes.
Do 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. |
|
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. |
var ErrIncompletePacket = errors.New("incomplete packet") const ( func (codec TcpCodec) Decode(c gnet.Conn) (*quote.BaseMsg, int, error) {
} 我在 OnTraffic 中调用 Decode 也报同样的错误, io.ErrShortBuffer 导致无法正常解析后续 tcp 报文, |
var ErrIncompletePacket = errors.New("incomplete packet") const ( func (codec TcpCodec) Decode(c gnet.Conn) (*quote.BaseMsg, int, error) { bodyLen := binary.LittleEndian.Uint32(buf[0:PacketSize]) msg := "e.BaseMsg{} I also reported the same error when calling Decode in OnTraffic. io.ErrShortBuffer caused the subsequent tcp messages to be unable to be parsed normally. |
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
The observability is far from the best since it is the simplest case. [gnet] 2024-04-28T15:52:50.015965+04:00 INFO logging/logger.go:256 Starting gnet client with 1 event-loop [gnet] 2024-04-28T15:52:50.016327+04:00 DEBUG logging/logger.go:249 default logging level is DEBUG [gnet] 2024-04-28T15:52:56.135536+04:00 DEBUG v2/reactor_default.go:105 event-loop(0) is exiting in terms of the demand from user, gnet: server is going to be shutdown
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
The text was updated successfully, but these errors were encountered: