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 · 4 comments · May be fixed by #354
Open

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

gomoripeti opened this issue Jun 11, 2024 · 4 comments · May be fixed by #354

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

@essen
Copy link
Member

essen commented Nov 12, 2024

If you'd like to work on this, this is a great time to do it as I will release a new version soon. Otherwise I will probably just change the listen return value to any() instead of atom().

@gomoripeti
Copy link
Author

sorry, I did not have time last week, so probably I wont' have time soon either :(

@juhlig juhlig linked a pull request Nov 18, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants