Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
I configured couchdb to accept ssl requests on port 6894 and put it behind haproxy, but the health checks were failing because of this error:
req_err(1419482684) unknown_error : function_clause [<<"prim_inet:sockname/1">>,<<"chttpd:absolute_uri/2 L541">>,<<"cloudant_plugin_chttpd:update_absolute_uri/1 L78">>,<<"cloudant_plugin_chttpd:before_request/1 L20">>,<<"lists:foldl/3 L1261">>,<<"chttpd_plugin:before_request/1 L30">>,<<"chttpd:before_request/1 L252">>,<<"chttpd:handle_request_int/1 L225">>]
I traced the problem to calling inet:sockname on an ssl socket:
https://github.com/apache/couchdb-chttpd/blob/master/src/chttpd.erl#L549
However, I didn't do a thorough audit to ensure there are no other places where an inet function might be called on an ssl socket.
In any case, a simple workaround is to change the "option httpchk" line in haproxy.cfg to something like this:
option httpchk GET /_up HTTP/1.0\r\nHost:\ some.host
which will avoid dropping into that particular case where the crashing code is called.
The simplest solution is to create a helper function that distinguishes between tcp and ssl sockets:
sockname(Socket) when is_pid(Socket) ->
inet:sockname(Socket);
sockname(Socket) when is_tuple(Socket) -> % is_tuple since ssl_api.hrl is not exposed
ssl:sockname(Socket).