fix(erlang): guard xdb:search against unconfigured pool
This commit is contained in:
parent
44013251b6
commit
d1dda93abd
|
|
@ -28,6 +28,10 @@ do_search(PoolName, Version, IpBin) ->
|
|||
CacheTable = ip2region_xdb:cache_table(Version),
|
||||
case ets:lookup(CacheTable, IpBin) of
|
||||
[{_, Region}] -> Region;
|
||||
_ ->
|
||||
case whereis(PoolName) of
|
||||
undefined ->
|
||||
{error, pool_not_configured};
|
||||
_ ->
|
||||
Worker = poolboy:checkout(PoolName, true, infinity),
|
||||
try
|
||||
|
|
@ -40,4 +44,5 @@ do_search(PoolName, Version, IpBin) ->
|
|||
after
|
||||
poolboy:checkin(PoolName, Worker)
|
||||
end
|
||||
end
|
||||
end.
|
||||
|
|
|
|||
|
|
@ -34,6 +34,14 @@ invalid_search_test_() ->
|
|||
?_assertEqual({error, bad_ip_format}, xdb:search({1,2,3}))
|
||||
].
|
||||
|
||||
ipv6_pool_not_configured_test() ->
|
||||
try application:stop(ip2region) catch _:_ -> ok end,
|
||||
try application:unload(ip2region) catch _:_ -> ok end,
|
||||
ok = application:load(ip2region),
|
||||
ok = application:set_env(ip2region, db, [{ipv4, "ip2region.xdb"}]),
|
||||
{ok, _} = application:ensure_all_started(ip2region),
|
||||
?assertEqual({error, pool_not_configured}, xdb:search("2001:4860:4860::8888")).
|
||||
|
||||
setup_ipv6() ->
|
||||
try application:stop(ip2region) catch _:_ -> ok end,
|
||||
try application:unload(ip2region) catch _:_ -> ok end,
|
||||
|
|
|
|||
Loading…
Reference in New Issue