fix(ipv6): add ipv6_probe socket option only when supported
ipv6_probe is a socket option supported in EMQ's otp.git fork. If the target hostname has a ipv6 DNS resolution, gen_tcp tries to establish a connection on ipv6. If it fails, then a fallback to default gen_tcp:connection
This commit is contained in:
parent
d9c7c72612
commit
a37f47887a
|
@ -60,7 +60,7 @@ translate_env(EnvName) ->
|
||||||
Path = path(Path0),
|
Path = path(Path0),
|
||||||
MoreOpts = case Scheme of
|
MoreOpts = case Scheme of
|
||||||
http ->
|
http ->
|
||||||
[{transport_opts, [ipv6_probe]}];
|
[{transport_opts, emqx_misc:ipv6_probe([])}];
|
||||||
https ->
|
https ->
|
||||||
CACertFile = application:get_env(?APP, cacertfile, undefined),
|
CACertFile = application:get_env(?APP, cacertfile, undefined),
|
||||||
CertFile = application:get_env(?APP, certfile, undefined),
|
CertFile = application:get_env(?APP, certfile, undefined),
|
||||||
|
@ -85,7 +85,7 @@ translate_env(EnvName) ->
|
||||||
, {ciphers, emqx_tls_lib:default_ciphers()}
|
, {ciphers, emqx_tls_lib:default_ciphers()}
|
||||||
| TLSOpts
|
| TLSOpts
|
||||||
],
|
],
|
||||||
[{transport, ssl}, {transport_opts, [ipv6_probe | NTLSOpts]}]
|
[{transport, ssl}, {transport_opts, emqx_misc:ipv6_probe(NTLSOpts)}]
|
||||||
end,
|
end,
|
||||||
PoolOpts = [{host, Host},
|
PoolOpts = [{host, Host},
|
||||||
{port, Port},
|
{port, Port},
|
||||||
|
|
|
@ -331,10 +331,12 @@ pool_opts(Params = #{<<"url">> := URL}, ResId) ->
|
||||||
PoolSize = maps:get(<<"pool_size">>, Params, 32),
|
PoolSize = maps:get(<<"pool_size">>, Params, 32),
|
||||||
ConnectTimeout =
|
ConnectTimeout =
|
||||||
cuttlefish_duration:parse(str(maps:get(<<"connect_timeout">>, Params, <<"5s">>))),
|
cuttlefish_duration:parse(str(maps:get(<<"connect_timeout">>, Params, <<"5s">>))),
|
||||||
TransportOpts = case Scheme =:= https of
|
TransportOpts0 =
|
||||||
true -> [ipv6_probe | get_ssl_opts(Params, ResId)];
|
case Scheme =:= https of
|
||||||
false -> [ipv6_probe]
|
true -> [get_ssl_opts(Params, ResId)];
|
||||||
end,
|
false -> []
|
||||||
|
end,
|
||||||
|
TransportOpts = emqx_misc:ipv6_probe(TransportOpts0),
|
||||||
Opts = case Scheme =:= https of
|
Opts = case Scheme =:= https of
|
||||||
true -> [{transport_opts, TransportOpts}, {transport, ssl}];
|
true -> [{transport_opts, TransportOpts}, {transport, ssl}];
|
||||||
false -> [{transport_opts, TransportOpts}]
|
false -> [{transport_opts, TransportOpts}]
|
||||||
|
|
|
@ -49,7 +49,7 @@ translate_env() ->
|
||||||
PoolSize = application:get_env(?APP, pool_size, 32),
|
PoolSize = application:get_env(?APP, pool_size, 32),
|
||||||
MoreOpts = case Scheme of
|
MoreOpts = case Scheme of
|
||||||
http ->
|
http ->
|
||||||
[{transport_opts, [ipv6_probe]}];
|
[{transport_opts, emqx_misc:ipv6_probe([])}];
|
||||||
https ->
|
https ->
|
||||||
CACertFile = application:get_env(?APP, cacertfile, undefined),
|
CACertFile = application:get_env(?APP, cacertfile, undefined),
|
||||||
CertFile = application:get_env(?APP, certfile, undefined),
|
CertFile = application:get_env(?APP, certfile, undefined),
|
||||||
|
@ -74,7 +74,7 @@ translate_env() ->
|
||||||
, {ciphers, emqx_tls_lib:default_ciphers()}
|
, {ciphers, emqx_tls_lib:default_ciphers()}
|
||||||
| TLSOpts
|
| TLSOpts
|
||||||
],
|
],
|
||||||
[{transport, ssl}, {transport_opts, [ipv6_probe | NTLSOpts]}]
|
[{transport, ssl}, {transport_opts, emqx_misc:ipv6_probe(NTLSOpts)}]
|
||||||
end,
|
end,
|
||||||
PoolOpts = [{host, Host},
|
PoolOpts = [{host, Host},
|
||||||
{port, Port},
|
{port, Port},
|
||||||
|
|
Loading…
Reference in New Issue