openresty / lua-resty-mysql

Nonblocking Lua MySQL driver library for ngx_lua or OpenResty
708 stars 236 forks source link

fix packet number overflow #55

Closed moonbingbing closed 7 years ago

moonbingbing commented 7 years ago

user bug report in google group : https://groups.google.com/forum/#!topic/openresty/j3a-x75x0D0

the packet number is uchar type, from 0 to 255. if overflow, the result should be equal with (uchar) net->pkt_nr++, which is from MySQL source code line 316 in function my_net_write : https://github.com/mysql/mysql-server/blob/71f48ab393bce80a59e5a2e498cd1f46f6b43f9a/sql/net_serv.cc

agentzh commented 7 years ago

Mind to add a test case to cover this case?

agentzh commented 7 years ago

Thanks for the patch!

moonbingbing commented 7 years ago

I will try to mock MySQL's response :)

vensontao commented 7 years ago

Is there anything I can do for this issue?

agentzh commented 7 years ago

@vensontao Please test the patch in this PR on your side. It's a bit more efficient than my patch you tried earlier :)

vensontao commented 7 years ago

Both the new patch and earlier patch, tested successfully, both can solve this problem, and bit.band(self.packet_no, 255) more efficient and pithy than earlier patch.
Well done! Thank you very much.

agentzh commented 7 years ago

Merged with minor edits. Thanks!