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

Validate the port number on connection settings #126

Open
mmmries opened this issue Jun 9, 2022 · 0 comments
Open

Validate the port number on connection settings #126

mmmries opened this issue Jun 9, 2022 · 0 comments

Comments

@mmmries
Copy link
Collaborator

mmmries commented Jun 9, 2022

Error messages from gen_tcp are not very helpful. Should we consider validating some connection arguments before calling the low-level libraries?

I paired with the head of devops at my current job because we were seeing a confusing error message in our staging environment.

iex([email protected])5> cfg = v(4)
%{
  host: "nats.raw.svc.cluster.local",
  port: "4222",
  tls: true,
  token: "somerandomtoken"
}
iex([email protected])6> Gnat.init(cfg)
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in :inet_tcp.getserv/1
(kernel 7.3) inet_tcp.erl:55: :inet_tcp.getserv("4222")
(kernel 7.3) gen_tcp.erl:181: :gen_tcp.connect1/4
    (kernel 7.3) gen_tcp.erl:165: :gen_tcp.connect/4
(gnat 1.2.0) lib/gnat/handshake.ex:9: Gnat.Handshake.connect/1
    (gnat 1.2.0) lib/gnat.ex:201: Gnat.init/1
(stdlib 3.14.1) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir 1.11.4) src/elixir.erl:280: :elixir.recur_eval/3
(elixir 1.11.4) src/elixir.erl:265: :elixir.eval_forms/3
    (iex 1.11.4) lib/iex/evaluator.ex:261: IEx.Evaluator.handle_eval/5
(iex 1.11.4) lib/iex/evaluator.ex:242: IEx.Evaluator.do_eval/3
    (iex 1.11.4) lib/iex/evaluator.ex:220: IEx.Evaluator.eval/3
    (iex 1.11.4) lib/iex/evaluator.ex:102: IEx.Evaluator.loop/1
    (iex 1.11.4) lib/iex/evaluator.ex:32: IEx.Evaluator.init/4
(stdlib 3.14.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
    (kernel 7.3) gen_tcp.erl:170: :gen_tcp.connect/4
(gnat 1.2.0) lib/gnat/handshake.ex:9: Gnat.Handshake.connect/1
    (gnat 1.2.0) lib/gnat.ex:201: Gnat.init/1

The port was configured as a string (read from an environment variable), but it took some poking at to realize what the problem was.

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

1 participant