openresty / lua-resty-mysql

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

need to close db connection if res is nil. #94

Open zhiyong0804 opened 5 years ago

zhiyong0804 commented 5 years ago

sw version : openresty 1.15.8.1, lua-resty-mysql commit id is 68f4841a. test step : 1. run the example of READ.md show, and if query failed will not call db:close

                 `
                     res, err, errcode, sqlstate = db:query("select * from catswhere id='100';") 
                     if not res then  
                            ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".");  
                            --db:close()  
                            return  
                      end  
                  `

             2.  check 3306 port status, there are so many TIME_WAIT socket

                  `
                      tcp        0      0 127.0.0.1:55532         127.0.0.1:3306          TIME_WAIT   -  
                      tcp        0      0 127.0.0.1:55534         127.0.0.1:3306          TIME_WAIT   -  
                 ` 

              3. add db:close when query res is nil, there is no any TIME_WAIT socket  

expect result : there is no any TIME_WAIT socket if query failed, so the examples show on README.md should add db:close if query failed.