CouchDB
  1. CouchDB
  2. COUCHDB-966

More explicit error messages when there are file access errors due to lack of permission

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1, 1.2
    • Component/s: Database Core
    • Labels:
      None
    • Environment:

      Any

      Description

      If you try to update the configuration settings, either through the API or Futon, but the underlying configuration files are not writable by the CouchDB process, the API response is '500', and the Futon response is just to appear to have frozen.

      Checking the log, you get this output:

      [Thu, 25 Nov 2010 12:51:45 GMT] [error] [<0.31700.81>] ** Generic server couch_config terminating

        • Last message in was {set,"uuids","algorithm","random",true}
        • When Server state ==
          Unknown macro: {config,[{<0.31726.81>,#Fun<couch_config.2.4103357>}, {<0.31719.81>,#Fun<couch_config.3.18912695>},
          {<0.31719.81>,#Fun<couch_config.3.18912695>}, {<0.31717.81>,#Fun<couch_config.2.4103357>}, {<0.31715.81>,#Fun<couch_config.2.4103357>}, {<0.31714.81>,#Fun<couch_config.2.4103357>},
          {<0.31714.81>,#Fun<couch_config.2.4103357>}, {<0.31712.81>,#Fun<couch_config.3.18912695>}, {<0.31711.81>,#Fun<couch_config.2.4103357>}, {<0.31709.81>,#Fun<couch_config.2.4103357>}, {false,#Fun<couch_server.3.123842465>}, {<0.31706.81>,#Fun<couch_config.3.18912695>}, {<0.31706.81>,#Fun<couch_config.2.4103357>}, {<0.6.0>,#Fun<couch_config.2.4103357>}], "/etc/couchdb/local.ini"}
        • Reason for termination ==
        • badmatch,{error,eacces,
          [ {couch_config_writer,save_to_file,2},
          {couch_config,handle_call,3},
          {gen_server,handle_msg,5},
          {proc_lib,init_p_do_apply,3}]}


          [Thu, 25 Nov 2010 12:51:45 GMT] [error] [<0.31700.81>] {error_report,<0.32.0>,
          {<0.31700.81>,crash_report,
          [[{initial_call,{couch_config,init,['Argument__1']}},
          {pid,<0.31700.81>},
          {registered_name,couch_config},
          {error_info,{exit,badmatch,{error,eacces,
          [{couch_config_writer,save_to_file,2}

          ,

          {couch_config,handle_call,3},
          {gen_server,handle_msg,5},
          {proc_lib,init_p_do_apply,3}]},
          [{gen_server,terminate,6},
          {proc_lib,init_p_do_apply,3}]}},
          {ancestors,[couch_server_sup,<0.33.0>]},
          {messages,[]},
          {links,[<0.79.0>]},
          {dictionary,[]},
          {trap_exit,false},
          {status,running},
          {heap_size,6765},
          {stack_size,24},
          {reductions,52930}],
          []]}}

          [Thu, 25 Nov 2010 12:51:45 GMT] [error] [<0.79.0>] {error_report,<0.32.0>,
          {<0.79.0>,supervisor_report,
          [{supervisor,{local,couch_server_sup}},
          {errorContext,child_terminated},
          {reason,
          badmatch,{error,eacces,
          [{couch_config_writer,save_to_file,2},
          {couch_config,handle_call,3}

          ,

          {gen_server,handle_msg,5},
          {proc_lib,init_p_do_apply,3}]}},
          {offender,
          [{pid,<0.31700.81>},
          {name,couch_config},
          {mfa,
          {couch_server_sup,couch_config_start_link_wrapper,
          [["/etc/couchdb/default.ini","/etc/couchdb/local.ini",
          "/etc/couchdb/default.ini","/etc/couchdb/local.ini"],
          <0.78.0>]}},
          {restart_type,permanent},
          {shutdown,brutal_kill},
          {child_type,worker}]}]}}

          [Thu, 25 Nov 2010 12:51:45 GMT] [error] [<0.31718.81>] Uncaught error in HTTP request: {exit,
          {badmatch,{error,eacces,
          [{couch_config_writer,save_to_file,2},
          {couch_config,handle_call,3},
          {gen_server,handle_msg,5}

          ,

          {proc_lib,init_p_do_apply,3}

          ]},

          Unknown macro: {gen_server,call, [couch_config, {set,"uuids","algorithm","random", true}]}

          }}

      None of this nicely points out that it is simply a file permission issue.

      1. COUCHDB-966.patch
        5 kB
        Filipe Manana
      2. COUCHDB-966.patch
        5 kB
        Filipe Manana

        Activity

        Hide
        Mike Baranczak added a comment -

        1. Regarding Filipe's patch: I don't know if it's a good idea to send the full path of the problematic file to a potentially untrusted client. This information should definitely be written to the log, but the HTTP response can be a little less informative. "Something went wrong, check the log" is perfectly OK. If I can't read the log, then I wouldn't be able to fix the permissions anyway.

        2. I'm using CouchDB 1.1.1 (installed on Mac OS via MacPorts), and I ran into something just like this. The directory /opt/local/var/run/couchdb didn't exist, and CouchDB didn't have the permissions to create it. Start-up failed with a completely non-descriptive error message. Should I open a separate ticket for this?

        Show
        Mike Baranczak added a comment - 1. Regarding Filipe's patch: I don't know if it's a good idea to send the full path of the problematic file to a potentially untrusted client. This information should definitely be written to the log, but the HTTP response can be a little less informative. "Something went wrong, check the log" is perfectly OK. If I can't read the log, then I wouldn't be able to fix the permissions anyway. 2. I'm using CouchDB 1.1.1 (installed on Mac OS via MacPorts), and I ran into something just like this. The directory /opt/local/var/run/couchdb didn't exist, and CouchDB didn't have the permissions to create it. Start-up failed with a completely non-descriptive error message. Should I open a separate ticket for this?
        Filipe Manana made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Hide
        Filipe Manana added a comment -

        Applied to trunk and 1.1.x

        Show
        Filipe Manana added a comment - Applied to trunk and 1.1.x
        Filipe Manana made changes -
        Summary Error log contents when the config files are not writable are not helpful More explicit error messages when there are file access errors due to lack of permission
        Fix Version/s 1.1 [ 12314933 ]
        Fix Version/s 1.2 [ 12315198 ]
        Hide
        MC Brown added a comment -

        This is a huge improvement on the error messages in these situations. No objections here.

        Show
        MC Brown added a comment - This is a huge improvement on the error messages in these situations. No objections here.
        Filipe Manana made changes -
        Attachment COUCHDB-966.patch [ 12467632 ]
        Hide
        Filipe Manana added a comment -

        Corrected a small mistake regarding the couch_config changes.

        Show
        Filipe Manana added a comment - Corrected a small mistake regarding the couch_config changes.
        Filipe Manana made changes -
        Assignee Filipe Manana [ fdmanana ]
        Filipe Manana made changes -
        Field Original Value New Value
        Attachment COUCHDB-966.patch [ 12467631 ]
        Hide
        Filipe Manana added a comment -

        Here's a patch that returns an explicit error when trying to access a file for which there's no read and/or write permission:

        Your configuration use case:

        $ curl -H 'X-Couch-Persist: true' -X PUT http://localhost:5984/_config/couchdb/delayed_commits -d '"false"'

        {"error":"file_permission_error","reason":"/home/fdmanana/git/hub/couchdb/etc/couchdb/local_dev.ini"}

        For a database file for which we don't have read permission:

        $ curl http://localhost:5984/abc

        {"error":"file_permission_error","reason":"/home/fdmanana/git/hub/couchdb/tmp/lib/abc.couch"}

        At startup when the user has no access to one of the critical files (log file, config files, _users database, etc):

        Apache CouchDB 1.2.0aac02c7b-git (LogLevel=info) is starting.

        =CRASH REPORT==== 6-Jan-2011::12:41:28 ===
        crasher:
        initial call: couch_event_sup:init/1
        pid: <0.80.0>
        registered_name: []
        exception exit:

        {file_permission_error, "/home/fdmanana/git/hub/couchdb/tmp/log/couch.log"}

        in function gen_server:init_it/6
        ancestors: [couch_primary_services,couch_server_sup,<0.32.0>]

        If nobody raise an objection, I'll commit it to trunk.

        Show
        Filipe Manana added a comment - Here's a patch that returns an explicit error when trying to access a file for which there's no read and/or write permission: Your configuration use case: $ curl -H 'X-Couch-Persist: true' -X PUT http://localhost:5984/_config/couchdb/delayed_commits -d '"false"' {"error":"file_permission_error","reason":"/home/fdmanana/git/hub/couchdb/etc/couchdb/local_dev.ini"} For a database file for which we don't have read permission: $ curl http://localhost:5984/abc {"error":"file_permission_error","reason":"/home/fdmanana/git/hub/couchdb/tmp/lib/abc.couch"} At startup when the user has no access to one of the critical files (log file, config files, _users database, etc): Apache CouchDB 1.2.0aac02c7b-git (LogLevel=info) is starting. =CRASH REPORT==== 6-Jan-2011::12:41:28 === crasher: initial call: couch_event_sup:init/1 pid: <0.80.0> registered_name: [] exception exit: {file_permission_error, "/home/fdmanana/git/hub/couchdb/tmp/log/couch.log"} in function gen_server:init_it/6 ancestors: [couch_primary_services,couch_server_sup,<0.32.0>] If nobody raise an objection, I'll commit it to trunk.
        MC Brown created issue -

          People

          • Assignee:
            Filipe Manana
            Reporter:
            MC Brown
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development