-
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
fixing bad connection error when reading large compressed packets #863
Conversation
I tried running your fork and got a panic, I'll work on getting a test case that I can share to reproduce.
|
That would be great. I'll take a look when you provide that. |
I've pushed one more change that may address the panic you found in your testing. There was a gap that could cause Also not sure why |
The latest commit fixed the panic I was seeing. Thank you. |
Fixed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will review later (on vacation)
packet/conn.go
Outdated
// if we've read to EOF, and we have compression then advance the sequence number | ||
// and reset the compressed reader to continue reading the remaining bytes | ||
// in the next compressed packet. | ||
if c.Compression != MYSQL_COMPRESS_NONE && rd < bcap && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just read the comment of ReadAtLeast
, seems for goErrors.Is(err, io.ErrUnexpectedEOF) || goErrors.Is(err, io.EOF)
we don't need to check rd < bcap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes agree with you after reviewing the ReadAtLeast
documentation. I've applied the change suggested.
packet/conn.go
Outdated
} | ||
|
||
// now read the remaining bytes into the buffer containing the first read bytes | ||
rd, err = io.ReadAtLeast(c.currentPacketReader(), buf[rd:], bcap-rd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we delete this reading and let the outer loop read it? because it may still meet the EOF error like line 191.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes terrific suggestion, i've applied this change.
return nil, nil | ||
} | ||
|
||
func (c *Conn) currentPacketReader() io.Reader { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there're
compressedReaderActive bool
compressedReader io.Reader
in Conn
. Seems we can directly check c.compressedReader == nil
as the returned reader for currentPacketReader
. And compressedReaderActive
always has the same value for c.compressedReader == nil
so we can delete it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I attempted to delete compressedReaderActive
the tests in the client
package all began failing when I ran them with compression enabled. I think this is because compressedReaderActive
is reset to false in WritePacket
after writing the compressed packet. So I don't think I can delete it, or at least I feel deleting it is out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this PR with your suggestion. It was 2am for me and I wasn't thinking clearly, but after more sleep, I realized I could easily remove the compressedReaderActive
boolean property from Conn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take care of your health ❤️
return nil, nil | ||
} | ||
|
||
func (c *Conn) currentPacketReader() io.Reader { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take care of your health ❤️
One of the commits after |
Do you happen to have a way to reproduce? Any other info that could help in diagnosing the issue? |
I'll get more information together and open an issue. |
Details posted in issue #871 |
This is a fix for #862