-
Notifications
You must be signed in to change notification settings - Fork 33
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
MMDB_free_entry_data_list (entry_data_list=0x23) at maxminddb.c:1860 #9
Comments
maybe u can delete my env$ cat /etc/os-release
## output
NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
Prerequisites
vhost config# lua_package_path '/path/to/your/lualib_dir/?.lua;;';
server {
listen 12345;
server_name 127.0.0.1;
location / {
content_by_lua_block {
local cjson = require 'cjson'
local geo = require 'resty.maxminddb'
geo.init("/path/to/GeoLite2-City.mmdb")
local res,err = geo.lookup(ngx.var.arg_ip or ngx.var.remote_addr) --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
if ((res or {}).country or {}).iso_code then
ngx.say(res['country']['iso_code'])
ngx.exit(ngx.HTTP_OK)
end
ngx.say('FAIL')
}
}
} run it$ curl http://127.0.0.1:12345/?ip=95.134.195.14
## output
full :{"subdivisions":[{"geoname_id":687699,"names":{"en":"Zaporizhia","ru":"Запорожская область","de":"Saporischschja","fr":"Oblast de Zaporijia"},"iso_code":"23"}],"city":{"geoname_id":687700,"names":{"en":"Zaporizhia","ru":"Запорожье","de":"Saporischschja","fr":"Zaporijia"}},"registered_country":{"geoname_id":690791,"names":{"en":"Ukraine","ru":"Украина","fr":"Ukraine","pt-BR":"Ucrânia","zh-CN":"乌克兰","es":"Ucrania","de":"Ukraine","ja":"ウクライナ共和国"},"iso_code":"UA"},"country":{"geoname_id":690791,"names":{"en":"Ukraine","ru":"Украина","fr":"Ukraine","pt-BR":"Ucrânia","zh-CN":"乌克兰","es":"Ucrania","de":"Ukraine","ja":"ウクライナ共和国"},"iso_code":"UA"},"continent":{"geoname_id":6255148,"names":{"en":"Europe","ru":"Европа","fr":"Europe","pt-BR":"Europa","zh-CN":"欧洲","es":"Europa","de":"Europa","ja":"ヨーロッパ"},"code":"EU"},"location":{"time_zone":"Europe\/Zaporozhye","longitude":35.2833,"accuracy_radius":50,"latitude":47.85},"postal":{"code":"70459"}}
UA |
when i deleted maxm.MMDB_free_entry_data_list(entry_data_list[0]) its not segfaulting!!! |
maybe u can change |
after i changed its failing with 2018/07/12 08:35:13 [error] 16499#16499: *1 lua entry thread aborted: runtime error: /usr/local/openresty/site/lualib/resty/maxminddb.lua:331: bad argument #1 to 'MMDB_free_entry_data_list' (cannot convert 'struct MMDB_entry_data_list_s **const' to 'struct MMDB_entry_data_list_s *const') |
emmm. it's work for ubuntu(mean's can u try command line for maxmind/libmaxminddb? $ mmdblookup --file /path/to/GeoLite2-City.mmdb --ip 95.134.195.14
## output
{
"city":
{
"geoname_id":
687700 <uint32>
"names":
{
"de":
"Saporischschja" <utf8_string>
"en":
"Zaporizhia" <utf8_string>
"fr":
"Zaporijia" <utf8_string>
"ru":
"Запорожье" <utf8_string>
}
}
"continent":
{
"code":
"EU" <utf8_string>
"geoname_id":
6255148 <uint32>
"names":
{
"de":
"Europa" <utf8_string>
"en":
"Europe" <utf8_string>
"es":
"Europa" <utf8_string>
"fr":
"Europe" <utf8_string>
"ja":
"ヨーロッパ" <utf8_string>
"pt-BR":
"Europa" <utf8_string>
"ru":
"Европа" <utf8_string>
"zh-CN":
"欧洲" <utf8_string>
}
}
"country":
{
"geoname_id":
690791 <uint32>
"iso_code":
"UA" <utf8_string>
"names":
{
"de":
"Ukraine" <utf8_string>
"en":
"Ukraine" <utf8_string>
"es":
"Ucrania" <utf8_string>
"fr":
"Ukraine" <utf8_string>
"ja":
"ウクライナ共和国" <utf8_string>
"pt-BR":
"Ucrânia" <utf8_string>
"ru":
"Украина" <utf8_string>
"zh-CN":
"乌克兰" <utf8_string>
}
}
"location":
{
"accuracy_radius":
50 <uint16>
"latitude":
47.850000 <double>
"longitude":
35.283300 <double>
"time_zone":
"Europe/Zaporozhye" <utf8_string>
}
"postal":
{
"code":
"70459" <utf8_string>
}
"registered_country":
{
"geoname_id":
690791 <uint32>
"iso_code":
"UA" <utf8_string>
"names":
{
"de":
"Ukraine" <utf8_string>
"en":
"Ukraine" <utf8_string>
"es":
"Ucrania" <utf8_string>
"fr":
"Ukraine" <utf8_string>
"ja":
"ウクライナ共和国" <utf8_string>
"pt-BR":
"Ucrânia" <utf8_string>
"ru":
"Украина" <utf8_string>
"zh-CN":
"乌克兰" <utf8_string>
}
}
"subdivisions":
[
{
"geoname_id":
687699 <uint32>
"iso_code":
"23" <utf8_string>
"names":
{
"de":
"Saporischschja" <utf8_string>
"en":
"Zaporizhia" <utf8_string>
"fr":
"Oblast de Zaporijia" <utf8_string>
"ru":
"Запорожская область" <utf8_string>
}
}
]
}
|
|
u can use use ref #6 (comment) |
cat server.conf
server {
listen 80;
server_name 127.0.0.1;
location / {
content_by_lua_block{
local cjson = require 'cjson'
local geo = require 'resty.maxminddb'
if not geo.initted() then
geo.init("/path/to/GeoLite2-City.mmdb")
end
local res,err = geo.lookup(ngx.var.arg_ip or ngx.var.remote_addr) --support ipv6 e.g. 2001:4860:0:1001::3004:ef68
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
}
}
} cat test.lua
wrk.method = "GET";
wrk.body = "";
logfile = io.open("wrk.log", "w");
request = function()
ip = tostring(math.random(1, 255)).."."..tostring(math.random(1, 255)).."."..tostring(math.random(1, 255)).."."..tostring(math.random(1, 255))
path = "/?ip=" .. ip
return wrk.format(nil, path)
end
response = function(status,header,body)
logfile:write("\nbody:" .. body .. "\n-----------------");
end ./wrk -t50 -c200 -d120s -s ./test.lua --latency http://127.0.0.1 delete
|
@anjia0532 Hey, I recently started using your library (thanks for your work on that, by the way!) and I am also hitting this problem in my environment. I can confirm that the segfault does go away when I comment out the line In maxmind/libmaxminddb#174, @oschwald suggests that this could happen while trying to free an uninitialized pointer. |
@jtammen paste your code plz. |
$ dpkg -l | grep maxmind
ii geoipupdate 2.5.0-0+maxmind1~xenial amd64 Tool for updating GeoIP and GeoLite databases
ii libmaxminddb-dev:amd64 1.3.2-0+maxmind1~xenial amd64 IP geolocation database library (development headers)
ii libmaxminddb0:amd64 1.3.2-0+maxmind1~xenial amd64 IP geolocation database library
ii mmdb-bin 1.3.2-0+maxmind1~xenial amd64 IP geolocation lookup command-line tool
$ geoipupdate
// upgrade to latest(Geo-City.mmdb)
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
$ uname -a
Linux openresty-server 4.4.0-127-generic #153-Ubuntu SMP Sat May 19 10:58:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ opm get anjia0532/lua-resty-maxminddb (install)
$ opm upgrade anjia0532/lua-resty-maxminddb (upgrade to latest version)
$ cat /path/to/resty/maxminddb.lua | grep _VERSION
_M._VERSION = '1.0.0' nginx's config
#ipv4
$ curl localhost/ip=114.114.114.114&node=city
#ipv6
#$ curl localhost/ip=2001:4860:0:1001::3004:ef68&node=country
full :{"city":{"geoname_id":1799962,"names":{"en":"Nanjing","ru":"Нанкин","fr":"Nankin","pt-BR":"Nanquim","zh-CN":"南京","es":"Nankín","de":"Nanjing","ja":"南京市"}},"subdivisions":[{"geoname_id":1806260,"names":{"en":"Jiangsu","fr":"Province de Jiangsu","zh-CN":"江苏省"},"iso_code":"32"}],"country":{"geoname_id":1814991,"names":{"en":"China","ru":"Китай","fr":"Chine","pt-BR":"China","zh-CN":"中国","es":"China","de":"China","ja":"中国"},"iso_code":"CN"},"registered_country":{"geoname_id":1814991,"names":{"en":"China","ru":"Китай","fr":"Chine","pt-BR":"China","zh-CN":"中国","es":"China","de":"China","ja":"中国"},"iso_code":"CN"},"location":{"time_zone":"Asia\/Shanghai","longitude":118.7778,"accuracy_radius":50,"latitude":32.0617},"continent":{"geoname_id":6255147,"names":{"en":"Asia","ru":"Азия","fr":"Asie","pt-BR":"Ásia","zh-CN":"亚洲","es":"Asia","de":"Asien","ja":"アジア"},"code":"AS"}}
node name:city ,value:{"geoname_id":1799962,"names":{"en":"Nanjing","ru":"Нанкин","fr":"Nankin","pt-BR":"Nanquim","zh-CN":"南京","es":"Nankín","de":"Nanjing","ja":"南京市"}} |
Server setup
nginx config
So in this sample configuration it actually works as expected. My real nginx configuration is a little different, though:
In nginx In After commenting out the line
So it might be related to the structure of the returned data from the database actually?! |
$ cat /etc/openresty/site/lualib/resty/maxminddb.lua | grep MMDB_free_entry_data_list
void MMDB_free_entry_data_list(MMDB_entry_data_list_s *const entry_data_list);
maxm.MMDB_free_entry_data_list(entry_data_list[0])
// not comment
$ curl localhost?ip=217.229.23.250\&node=city
full :{"subdivisions":[{"geoname_id":2911297,"names":{"en":"Hamburg","fr":"Hambourg","de":"Hamburg","es":"Hamburgo"},"iso_code":"HH"}],"city":{"geoname_id":2911298,"names":{"en":"Hamburg","ru":"Гамбург","fr":"Hambourg","pt-BR":"Hamburgo","zh-CN":"汉堡市","es":"Hamburgo","de":"Hamburg","ja":"ハンブルク"}},"registered_country":{"geoname_id":2921044,"names":{"en":"Germany","ru":"Германия","fr":"Allemagne","pt-BR":"Alemanha","zh-CN":"德国","es":"Alemania","de":"Deutschland","ja":"ドイツ連邦共和国"},"iso_code":"DE","is_in_european_union":false},"country":{"geoname_id":2921044,"names":{"en":"Germany","ru":"Германия","fr":"Allemagne","pt-BR":"Alemanha","zh-CN":"德国","es":"Alemania","de":"Deutschland","ja":"ドイツ連邦共和国"},"iso_code":"DE","is_in_european_union":false},"continent":{"geoname_id":6255148,"names":{"en":"Europe","ru":"Европа","fr":"Europe","pt-BR":"Europa","zh-CN":"欧洲","es":"Europa","de":"Europa","ja":"ヨーロッパ"},"code":"EU"},"location":{"time_zone":"Europe\/Berlin","longitude":10.1669,"accuracy_radius":5,"latitude":53.6063},"postal":{"code":"22143"}}
node name:city ,value:{"geoname_id":2911298,"names":{"en":"Hamburg","ru":"Гамбург","fr":"Hambourg","pt-BR":"Hamburgo","zh-CN":"汉堡市","es":"Hamburgo","de":"Hamburg","ja":"ハンブルク"}} it's work. |
@anjia0532 Yes, it works with the sample nginx config (first one in my comment) but not my "real" config, i.e. using |
yeap,works too. |
I am not an expert with Lua, but this code appears to be ignoring the value in lua-resty-maxminddb/lib/resty/maxminddb.lua Lines 328 to 331 in 702629d
If there is an error, you should not try it iterate over the entry_data_list or call |
@anjia0532 @oschwald Thanks for your effort … I did the upgrade, but unfortunately, that did not change anything for me, still segfaulting :-/ It still works for me if I change this line in my Lua script:
to this using the sample IP:
Or commenting out the line
So I still think it has to do with the actual data for the specific IP address. As I am neither an expert in Lua nor C++, I fear there is nothing more that I could contribute. So I am looking at some other solutions for my requirements now. Thanks again for your effort! Edit: I just noticed sth (even more) strange: When I get a segfault and then do a completely unrelated changed in the |
ps: |
@anjia0532 Thanks, this seems to work, at least the segfaults are gone now! Didn't have the time yet to do some benchmarking yet, so I don't know if this could be used in production environment :) |
@jtammen fixed,upgrade to v1.2.0 thanks for @spacewander (PR #14) |
still segfaulting, even in version 0.6
The text was updated successfully, but these errors were encountered: