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

Minor: ranch_ssl:listen can return non-atom error reasons #346

Open
gomoripeti opened this issue Jun 11, 2024 · 2 comments
Open

Minor: ranch_ssl:listen can return non-atom error reasons #346

gomoripeti opened this issue Jun 11, 2024 · 2 comments

Comments

@gomoripeti
Copy link

gomoripeti commented Jun 11, 2024

According to the ranch_transport behaviour, listen/1 callback should return only atoms as error reasons https://github.com/ninenines/ranch/blob/master/src/ranch_transport.erl#L31. However ssl:listen and hence ranch_ssl:listen/1 can return more sophisticated error reasons as visible in ssl:format_error/1.

A quick fix would be to use ssl:format_error instead of inet:format_error in (

inet:format_error(Reason).
) (the former fall back to the later so works for non-ssl connections too)

Maybe a more generic solution would be if Transport behaviour would have an optional format_error callback and ranch_ssl would implement it calling ssl:format_error.

Not sure which one is preferred?

As an example the below crash happens if a non-existing cipher is provided in the options (seen with Erlang 26.2.5)

{failed_to_start_child,ranch_acceptors_sup,
 {badarg,
  [{erlang,atom_to_binary,
    [{options,
      {ciphers,
       [
       ...
       ]}}],
    [{error_info,#{module => erl_erts_errors}}]},
   {erl_posix_msg,message_1,1,
    [{file,"erl_posix_msg.erl"},{line,175}]},
   {erl_posix_msg,message,1,
    [{file,"erl_posix_msg.erl"},{line,29}]},
   {ranch_acceptors_sup,listen_error,5,
    [{file,"src/ranch_acceptors_sup.erl"},
     {line,95}]},
   {ranch_acceptors_sup,start_listen_sockets,5,
    [{file,"src/ranch_acceptors_sup.erl"},
     {line,54}]},
   {ranch_acceptors_sup,init,1,
    [{file,"src/ranch_acceptors_sup.erl"},
     {line,34}]},

@essen
Copy link
Member

essen commented Jun 12, 2024

An optional format_error callback is probably the best solution.

@gomoripeti
Copy link
Author

thanks for the feedback, I will work on a patch

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

2 participants