CouchDB
  1. CouchDB
  2. COUCHDB-1512

Provide proper error if a hostname (and not an ip) is used for bind_address

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3
    • Component/s: None
    • Labels:
      None

      Description

      Currently, couch throws an opaque error message and doesn't bind the tcp port, but the process doesn't die, so it's unclear what's happening. Preferably, couch should raise an informative error message and die if an invalid bind_address is passed

        Activity

        Hide
        Dave Cottlehuber added a comment -

        Here's a patch that should address it, error & stack trace now looks like this for [httpd] bind_address = foo.bar

        BindAddress is invalid: foo.bar
        [error] [<0.97.0>] {error_report,<0.35.0>,
        {<0.97.0>,supervisor_report,
        [{supervisor,{local,couch_secondary_services}},

        {errorContext,start_error}

        ,

        {reason,invalid_bind_address}

        ,

        Andrew what platform was this on and how was CouchDB started? I don't get the hung VM that you report, just a straight exit + stacktrace.

        diff --git i/src/couchdb/couch_httpd.erl w/src/couchdb/couch_httpd.erl
        index 7329c3b..a494178 100644
        — i/src/couchdb/couch_httpd.erl
        +++ w/src/couchdb/couch_httpd.erl
        @@ -97,6 +97,14 @@ start_link(Name, Options) ->
        % will restart us and then we will pick up the new settings.

        BindAddress = couch_config:get("httpd", "bind_address", any),
        + % ensure BindAddress is not symbolic hostname. Fixes COUCHDB-1512.
        + case inet_parse:address(BindAddress) of
        +

        {ok, _BindAddress}

        -> BindAddress;
        + _ ->
        + io:format("BindAddress is invalid: ~s~n", [BindAddress]),
        + throw(

        {error, invalid_bind_address}

        )
        + end,
        +
        DefaultSpec = "

        {couch_httpd_db, handle_request}

        ",
        DefaultFun = make_arity_1_fun(
        couch_config:get("httpd", "default_handler", DefaultSpec)

        #1 I assume it's OK to use inet_parse:address even though it's not specifically documented, but is referred to in www.erlang.org/doc/man/inet.html

        #2 It seems during start_link/2 we only return errors via io:format rather than ?LOG macros. Is there a good reason for that?

        Show
        Dave Cottlehuber added a comment - Here's a patch that should address it, error & stack trace now looks like this for [httpd] bind_address = foo.bar BindAddress is invalid: foo.bar [error] [<0.97.0>] {error_report,<0.35.0>, {<0.97.0>,supervisor_report, [{supervisor,{local,couch_secondary_services}}, {errorContext,start_error} , {reason,invalid_bind_address} , Andrew what platform was this on and how was CouchDB started? I don't get the hung VM that you report, just a straight exit + stacktrace. diff --git i/src/couchdb/couch_httpd.erl w/src/couchdb/couch_httpd.erl index 7329c3b..a494178 100644 — i/src/couchdb/couch_httpd.erl +++ w/src/couchdb/couch_httpd.erl @@ -97,6 +97,14 @@ start_link(Name, Options) -> % will restart us and then we will pick up the new settings. BindAddress = couch_config:get("httpd", "bind_address", any), + % ensure BindAddress is not symbolic hostname. Fixes COUCHDB-1512 . + case inet_parse:address(BindAddress) of + {ok, _BindAddress} -> BindAddress; + _ -> + io:format("BindAddress is invalid: ~s~n", [BindAddress] ), + throw( {error, invalid_bind_address} ) + end, + DefaultSpec = " {couch_httpd_db, handle_request} ", DefaultFun = make_arity_1_fun( couch_config:get("httpd", "default_handler", DefaultSpec) #1 I assume it's OK to use inet_parse:address even though it's not specifically documented, but is referred to in www.erlang.org/doc/man/inet.html #2 It seems during start_link/2 we only return errors via io:format rather than ?LOG macros. Is there a good reason for that?

          People

          • Assignee:
            Dave Cottlehuber
            Reporter:
            Andrew Melo
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development