Skip to content
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

Error at lookup IP #5

Closed
diegogub opened this issue May 21, 2018 · 14 comments
Closed

Error at lookup IP #5

diegogub opened this issue May 21, 2018 · 14 comments

Comments

@diegogub
Copy link

diegogub commented May 21, 2018

172.17.0.1 - - [21/May/2018:11:55:04 +0000] "GET / HTTP/1.1" 200 0 "-" "curl/7.54.0"
2018/05/21 11:55:04 [error] 6#6: *5 lua entry thread aborted: runtime error: /usr/local/openresty/site/lualib/resty/maxminddb.lua:323: bad argument #1 to 'concat' (table expected, got nil)
stack traceback:
coroutine 0:
[C]: in function 'concat'
/usr/local/openresty/site/lualib/resty/maxminddb.lua:323: in function 'lookup'
/src/geo.lua:6: in function </src/geo.lua:1>, client: 172.17.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8081"

@anjia0532
Copy link
Owner

double #4.
u need check prerequisites by https://github.com/anjia0532/lua-resty-maxminddb#prerequisites

anjia0532 added a commit that referenced this issue May 22, 2018
@diegogub
Copy link
Author

@anjia0532 thanks! but not Im getting:
172.17.0.1 - - [22/May/2018:02:41:02 +0000] "GET / HTTP/1.1" 500 199 "-" "curl/7.54.0"
2018/05/22 02:41:02 [error] 5#5: *1 lua entry thread aborted: runtime error: /usr/local/openresty/site/lualib/resty/maxminddb.lua:324: Expected value but found T_END at character 1
stack traceback:
coroutine 0:
[C]: in function 'json_decode'

@anjia0532
Copy link
Owner

anjia0532 commented May 22, 2018

try again plz.

return json_decode(table.concat(resultTab or {'{','}'})),nil -- fix https://github.com/anjia0532/lua-resty-maxminddb/issues/5#issuecomment-390845118

can u install libmaxminddb lib?

@diegogub
Copy link
Author

diegogub commented May 22, 2018

@anjia0532 It's already installed..now it's working but I'm getting empty table.

@anjia0532
Copy link
Owner

anjia0532 commented May 22, 2018

this lab is work for me , can u paste your test ip?or u can add some code to debug.

e.g. print data_type at

I think the problem should be in

else
entry_data_item = entry_data_list[0].entry_data
data_type = entry_data_item.type
data_size = entry_data_item.data_size
local val
-- string type "key":"val"
-- other type "key":val
-- default other type
local fmt="%s"
if data_type == MMDB_DATA_TYPE_UTF8_STRING then
val = ffi_str(entry_data_item.utf8_string,data_size)
fmt='"%s"'
if not val then
status = MMDB_OUT_OF_MEMORY_ERROR
return nil,status,resultTab
end
elseif data_type == MMDB_DATA_TYPE_BYTES then
val = ffi_str(ffi_cast('char * ',entry_data_item.bytes),data_size)
fmt='"%s"'
if not val then
status = MMDB_OUT_OF_MEMORY_ERROR
return nil,status,resultTab
end
elseif data_type == MMDB_DATA_TYPE_DOUBLE then
val = entry_data_item.double_value
elseif data_type == MMDB_DATA_TYPE_FLOAT then
val = entry_data_item.float_value
elseif data_type == MMDB_DATA_TYPE_UINT16 then
val = entry_data_item.uint16
elseif data_type == MMDB_DATA_TYPE_UINT32 then
val = entry_data_item.uint32
elseif data_type == MMDB_DATA_TYPE_BOOLEAN then
val = entry_data_item.boolean == 1
elseif data_type == MMDB_DATA_TYPE_UINT64 then
val = entry_data_item.uint64
elseif data_type == MMDB_DATA_TYPE_INT32 then
val = entry_data_item.int32
else
return nil,MMDB_INVALID_DATA_ERROR,resultTab
end
table.insert(resultTab,(fmt):format(val))
entry_data_list = entry_data_list[0].next
end
status = MMDB_SUCCESS

good luck

@diegogub
Copy link
Author

diegogub commented May 22, 2018

 local cjson = require 'cjson'
  local geo = require 'resty.maxminddb'

  local maxm = geo.new("/srv/geo.mmdb")

  local res,err = maxm:lookup("103.23.202.156") --support ipv6 e.g. 2001:4860:0:1001::3004:ef68

  if not res then
    ngx.log(ngx.ERR,'failed to lookup by ip ,reason:',err)
  end

  ngx.say("full :",cjson.encode(res))
  if ngx.var.arg_node then
    ngx.say("node name:",ngx.var.arg_node," ,value:", cjson.encode(res[ngx.var.arg_node] or {}))
  end

This is my code

@anjia0532
Copy link
Owner

anjia0532 commented May 22, 2018

geo.new("/srv/geo.mmdb")

is this db file (/srv/geo.mmdb) download from http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz ? (GeoLite2-City.mmdb?)

@jloh
Copy link
Contributor

jloh commented May 29, 2018

I can't get this module to work either with openresty v1.13.6.2. Installed v0.03 of lua-resty-maxminddb via OPM. I've got all the prerequisites installed but res always seems to be empty.

Code:

location /test {
    default_type application/json;
    content_by_lua_block {
        local cjson = require 'cjson'
        local geo = require 'resty.maxminddb'
        local maxm = geo.new('/tmp/GeoLite2-City_20180501/GeoLite2-City.mmdb')
        local res,err = maxm:lookup(ngx.var.arg_ip or ngx.var.remote_addr)
        ngx.say(cjson.encode(res))
    }
}

Here's what data_type ends up looking like:

2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 6, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 6, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 6, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 5, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 3, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 3, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 6, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 11, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 6, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 7, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"
2018/05/29 07:06:25 [error] 28408#28408: *1 [lua] maxminddb.lua:181: _dump_entry_data_list(): debug data: 2, client: 10.0.2.2, server: localhost, request: "GET /test/ip=114.114.114.114 HTTP/1.1", host: "localhost:8090"

@anjia0532
Copy link
Owner

@jloh It's my fault.

return json_decode(table.concat(resultTap or {'{','}'})),nil -- fix https://github.com/anjia0532/lua-resty-maxminddb/issues/5#issuecomment-390845118

at v0.03 the var resultTab ,is wrong. u will upgrade to v0.04

@jloh
Copy link
Contributor

jloh commented May 30, 2018

@anjia0532 I could never get any exceptions to fire, I just can't get the module to return any geo data at this stage, it always just returns blank/an empty JSON array. Tried the change you've suggested but got the same thing:

$ http localhost:8090/test?ip=8.8.8.8
HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: application/json
Date: Wed, 30 May 2018 01:57:22 GMT
Server: openresty/1.13.6.2
Transfer-Encoding: chunked

{}

Config:

location /test {
    default_type application/json;
    content_by_lua_block {
        local cjson = require 'cjson'
        local geo = require 'resty.maxminddb'
        local maxm = geo.new('/tmp/GeoLite2-City_20180501/GeoLite2-City.mmdb')
        local res,err = maxm:lookup(ngx.var.arg_ip or ngx.var.remote_addr)
        ngx.say(res)
    }
}

Tested it against 8.8.8.8 as well:

$ http localhost:8090/test?ip=8.8.8.8
HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: application/json
Date: Wed, 30 May 2018 01:59:33 GMT
Server: openresty/1.13.6.2
Transfer-Encoding: chunked

{}

@anjia0532
Copy link
Owner

your local lua-resty-maxminddb version? v0.03?

  1. /path/to/openresty/bin/opm upgrade anjia0532/lua-resty-maxminddb (Fetching anjia0532/lua-resty-maxminddb > 0.03 Downloading https://opm.openresty.org/api/pkg/tarball/anjia0532/lua-resty-maxminddb-0.04.opm.tar.gz)
  2. /path/to/openresty/bin/openresty -s reload
  3. curl localhost:8090/test?ip=8.8.8.8
  4. output
{"country":{"geoname_id":6252001,"names":{"en":"United States","ru":"США","fr":"États-Unis","pt-BR":"Estados Unidos","zh-CN":"美国","es":"Estados Unidos","de":"USA","ja":"アメリカ合衆国"},"iso_code":"US"},"registered_country":{"geoname_id":6252001,"names":{"en":"United States","ru":"США","fr":"États-Unis","pt-BR":"Estados Unidos","zh-CN":"美国","es":"Estados Unidos","de":"USA","ja":"アメリカ合衆国"},"iso_code":"US"},"continent":{"geoname_id":6255149,"names":{"en":"North America","ru":"Северная Америка","fr":"Amérique du Nord","pt-BR":"América do Norte","zh-CN":"北美洲","es":"Norteamérica","de":"Nordamerika","ja":"北アメリカ"},"code":"NA"},"location":{"longitude":-97.822,"accuracy_radius":1000,"latitude":37.751}}

@jloh
Copy link
Contributor

jloh commented May 30, 2018

Sorry @anjia0532! I didn't see your update. I can confirm that updating to v0.04 has got it all working for me!

@anjia0532
Copy link
Owner

@jloh Cheers

@zhannk
Copy link

zhannk commented Dec 7, 2018

local cjson=require 'cjson'
local geo=require 'resty.maxminddb'

local arg_ip=ngx.var.arg_ip
local arg_node=ngx.var.arg_node

ngx.say("IP:",arg_ip,", Node:",arg_node,"
")

if not geo.initted() then
geo.init("/usr/local/openresty/nginx/conf/lua/GeoLite2-City.mmdb")
end

local res,err=geo.lookup(arg_ip or ngx.var.remote_addr)

if not res then
ngx.say("Please check the ip address you provided:

",arg_ip,"
")
ngx.log(ngx.ERR,' failed to lookup by ip , reason :',err)
else
ngx.say("Result:",cjson.encode(res))

    if arg_node then
            ngx.say("<br>Node name:",arg_node, "<br>Value:",cjson.encode(res[arg_node] or {}))

    end

-- ngx.say(cjson.encode(res['country']))
-- ngx.say(cjson.encode(res['city']['names']['zh-CN']))

end

上面这段代码在 curl -k -L "http://192.168.137.70/lua?ip=111.47.224.182&node=subdivisions" 出现异常了 2018/12/07 15:51:23 [alert] 6466#0: worker process 13218 exited on signal 11
dmesg显示:
[24198.721511] openresty[12676]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24356.262054] openresty[13125]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24417.535463] openresty[13486]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24605.925152] openresty[13030]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24742.409458] traps: openresty[13355] trap stack segment ip:7f3b320e88e0 sp:7ffc488d6700 error:0 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24768.654847] openresty[13453]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24875.143743] traps: openresty[13602] trap stack segment ip:7f3b320e88e0 sp:7ffc488d6700 error:0 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24978.362300] openresty[13628]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24985.536349] openresty[13495]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24986.341160] openresty[13541]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[24987.163714] openresty[13677]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[25053.506562] openresty[13683]: segfault at 7b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]
[27040.935473] openresty[13218]: segfault at 5b ip 00007f3b320e7e45 sp 00007ffc488d6718 error 4 in libmaxminddb.so.0.0.7[7f3b320e5000+5000]

@anjia0532 anjia0532 mentioned this issue Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants