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
lua-resty-mysql variable self.packet_no bug #212
Comments
@vensontao Yeah, this is a corner case that the client sends more than 255 packets through a single diff --git a/lib/resty/mysql.lua b/lib/resty/mysql.lua
index 008a267..fc8bb74 100644
--- a/lib/resty/mysql.lua
+++ b/lib/resty/mysql.lua
@@ -184,11 +184,16 @@ end
local function _send_packet(self, req, size)
local sock = self.sock
- self.packet_no = self.packet_no + 1
+ local packet_no = self.packet_no
+ packet_no = packet_no + 1
+ if packet_no >= 256 then
+ packet_no = 1
+ end
+ self.packet_no = packet_no
-- print("packet no: ", self.packet_no)
- local packet = _set_byte3(size) .. strchar(self.packet_no) .. req
+ local packet = _set_byte3(size) .. strchar(packet_no) .. req
-- print("sending packet: ", _dump(packet)) |
Great, This problem has been solved. thanks very much! |
Great,I try the following patch you gave, the problem has been solved. And I close the issues on GitHub. Thank you very much!
发件人: Yichun Zhang [mailto:notifications@github.com]
发送时间: 2016年12月14日 5:16
收件人: openresty/openresty
抄送: vensontao; Mention
主题: Re: [openresty/openresty] lua-resty-mysql variable self.packet_no bug (#212)
@vensontao <https://github.com/vensontao> Yeah, this is a corner case that the client sends more than 255 packets through a single resty.mysql object. We should check the integer overflow. Will you try the following patch on your side?
diff --git a/lib/resty/mysql.lua b/lib/resty/mysql.lua
index 008a267..fc8bb74 100644
--- a/lib/resty/mysql.lua
+++ b/lib/resty/mysql.lua
@@ -184,11 +184,16 @@ end
local function _send_packet(self, req, size)
local sock = self.sock
- self.packet_no = self.packet_no + 1
+ local packet_no = self.packet_no
+ packet_no = packet_no + 1
+ if packet_no >= 256 then
+ packet_no = 1
+ end
+ self.packet_no = packet_no
…-- print("packet no: ", self.packet_no)
- local packet = _set_byte3(size) .. strchar(self.packet_no) .. req
+ local packet = _set_byte3(size) .. strchar(packet_no) .. req
-- print("sending packet: ", _dump(packet))
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#212 (comment)> , or mute the thread <https://github.com/notifications/unsubscribe-auth/APAJkHEsp_sVx7Er3bqerT6LTXzIBitbks5rHwshgaJpZM4LLWgt> . <https://github.com/notifications/beacon/APAJkLBhDgPLCq_hRpFZlnw5E5lXYV74ks5rHwshgaJpZM4LLWgt.gif>
|
we can fix this issue in the next version of openresty/lua-resty-mysql. |
mrytsr
pushed a commit
to bilibili/lua-resty-mysql
that referenced
this issue
Apr 22, 2018
Mentioned by this issue openresty/openresty#212 Maybe better fix with one line
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lualib/resty/mysql.lua:191: bad argument #1 to 'strchar' (invalid value)
in mysql.lua file, the fucntion _send_packet(self, req, size)
self.packet_no = self.packet_no + 1
local packet = _set_byte3(size) .. strchar(self.packet_no) .. req
the variables self.packet_no can be 255 +1 =256, produce errors: bad argument #1 to 'strchar' (invalid value)
detail error information see openresty group url:
https://groups.google.com/forum/#!topic/openresty/j3a-x75x0D0
The text was updated successfully, but these errors were encountered: