CouchDB
  1. CouchDB
  2. COUCHDB-537

CouchDB crushes for unknown builtin reduce function string

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.10
    • Fix Version/s: None
    • Component/s: Database Core
    • Labels:
      None
    • Environment:

      ubuntu from source 0.10

    • Skill Level:
      New Contributors Level (Easy)

      Description

      For a simple reduce as _sum if i add a space after _sum it crashes.
      Don't know how likely it is to add a space by mistake maybe the input could be trimed ?

        Activity

        Hide
        Nils Adermann added a comment -

        Rather than trimming the value, this patch throws an error message explaining that the builtin function of that name does not exist. This also helps people who put other kinds of typos in there.

        Show
        Nils Adermann added a comment - Rather than trimming the value, this patch throws an error message explaining that the builtin function of that name does not exist. This also helps people who put other kinds of typos in there.
        Hide
        Nils Adermann added a comment - - edited

        Updated the patch to include a test. It's also in github if that is of any use: http://github.com/naderman/couchdb/commit/cb1ae200d81d5eaad301ad71fb85d50ccb072904

        Show
        Nils Adermann added a comment - - edited Updated the patch to include a test. It's also in github if that is of any use: http://github.com/naderman/couchdb/commit/cb1ae200d81d5eaad301ad71fb85d50ccb072904
        Hide
        Jan Lehnardt added a comment -

        Nils, good patch, can you rebase this for master?

        Show
        Jan Lehnardt added a comment - Nils, good patch, can you rebase this for master?
        Hide
        Adam Lofts added a comment -

        I've rebased this patch to master.

        Show
        Adam Lofts added a comment - I've rebased this patch to master.
        Hide
        Adam Kocoloski added a comment -

        Current status is that master ignores trailing characters (whitespace or otherwise) when looking for builtins. It still doesn't do anything polite when a user sets "reduce": "_randomthing".

        Show
        Adam Kocoloski added a comment - Current status is that master ignores trailing characters (whitespace or otherwise) when looking for builtins. It still doesn't do anything polite when a user sets "reduce": "_randomthing".
        Hide
        Alexander Shorin added a comment -

        Fix issue summary and raise priority since CouchDB doesn't even returns HTTP 500 response. Just closes connection for case of invalid builtin reduce function call:

        CouchDB:

        {"couchdb":"Welcome","uuid":"df0eb380548d633a317f3b13c99c8f16","version":"1.4.0+build.8d7ab8b","vendor":{"version":"1.4.0+build.8d7ab8b","name":"The Apache Software Foundation"}}
        

        ddoc:

        {
            "_id": "_design/foo", 
            "_rev": "3-f7b8e13dcaf9fbe69a63d2717fbbba16", 
            "language": "javascript", 
            "views": {
                "bar": {
                    "map": "function(doc) {\n  emit(null, doc);\n}", 
                    "reduce": "_foobar"
                }
            }
        }
        

        view call:

        curl -v http://localhost:5984/apps/_design/foo/_view/bar
        * Adding handle: conn: 0x1c67fa0
        * Adding handle: send: 0
        * Adding handle: recv: 0
        * Curl_addHandleToPipeline: length: 1
        * - Conn 0 (0x1c67fa0) send_pipe: 1, recv_pipe: 0
        * About to connect() to localhost port 5984 (#0)
        *   Trying 127.0.0.1...
        * Connected to localhost (127.0.0.1) port 5984 (#0)
        > GET /apps/_design/foo/_view/bar HTTP/1.1
        > User-Agent: curl/7.30.0
        > Host: localhost:5984
        > Accept: */*
        > 
        * Empty reply from server
        * Connection #0 to host localhost left intact
        curl: (52) Empty reply from server
        

        crush log:

        [Tue, 25 Jun 2013 20:38:26 GMT] [info] [<0.487.0>] Starting index update for db: apps idx: _design/foo
        [Tue, 25 Jun 2013 20:38:26 GMT] [error] [emulator] Error in process <0.733.0> with exit value: {function_clause,[{couch_query_servers,builtin_reduce,[reduce,[<<7 bytes>>],[[[null,<<32 bytes>>],{[{<<3 bytes>>,<<32 bytes>>},{<<4 bytes>>,<<34 bytes>>},{<<5 bytes>>,{[{<<6 bytes>>,null},{<<9 bytes>>,1365117683},{<<10 bytes>>,<<25 bytes>>},{<<10 bytes>>,<<25 bytes>>},{<<4 bytes>>,null},{<<4 bytes>>,<<9 bytes>>},{<<4 bytes>>,<<7 bytes>>}]}}]}],[[null,<<32 bytes>>],{[{<<3 bytes>>,<<32 bytes>>},{<<4 bytes>>,<<34 bytes>>},{<<5 bytes>>,{[{<<6 bytes>>,null},{<<9 bytes>>,1365117839},{<<10 bytes>>,<<25 bytes>>},{<<10 bytes>>,<<25 bytes>>},{<<4 bytes>>,null},{<<4 bytes>>,<<9 bytes>>},{<<4 bytes>>,<<7 bytes>>}]}}]}],[[null,<<32 bytes>>],{[{<<3 bytes>>,<<32 bytes>>},{<<4 bytes>>,<<34 bytes>>},{<<5 bytes>>,{[{<<6 bytes>>,null},{<<9 bytes>>,1365117844},{<<10 bytes>>,<<25 bytes>>},{<<10 bytes>>,<<25 bytes>>},{... 
        
        
        [Tue, 25 Jun 2013 20:38:26 GMT] [error] [<0.545.0>] {error_report,<0.31.0>,
                             {<0.545.0>,crash_report,
                              [[{initial_call,
                                 {mochiweb_acceptor,init,
                                  ['Argument__1','Argument__2','Argument__3']}},
                                {pid,<0.545.0>},
                                {registered_name,[]},
                                {error_info,
                                 {error,badarg,
                                  [{erlang,list_to_binary,
                                    [[{couch_query_servers,builtin_reduce,
                                       [reduce,
                                        [<<"_foobar">>],
                                        [[[null,
                                           <<"3f5046939ff05dec5d04747d6b0058c6">>],
                                          {[{<<"_id">>,
                                             <<"3f5046939ff05dec5d04747d6b0058c6">>},
                                            {<<"_rev">>,
                                             <<"1-93d47d1072a9b7c66c35b278eb8a9766">>},
                                            {<<".meta">>,
                                             {[{<<"author">>,null},
                                               {<<"timestamp">>,1365117683},
                                               {<<"created_at">>,
                                                <<"2013-04-05T03:21:23+00:00">>},
                                               {<<"updated_at">>,
                                                <<"2013-04-05T03:21:23+00:00">>},
                                               {<<"user">>,null},
                                               {<<"peer">>,<<"127.0.0.1">>},
                                               {<<"type">>,<<"generic">>}]}}]}],
                                         [[null,
                                           <<"3f5046939ff05dec5d04747d6b0061eb">>],
                                          {[{<<"_id">>,
                                             <<"3f5046939ff05dec5d04747d6b0061eb">>},
                                            {<<"_rev">>,
                                             <<"1-f6374d2b14f1e7164d596a3b030340b3">>},
                                            {<<".meta">>,
                                             {[{<<"author">>,null},
                                               {<<"timestamp">>,1365117839},
                                               {<<"created_at">>,
                                                <<"2013-04-05T03:23:59+00:00">>},
                                               {<<"updated_at">>,
                                                <<"2013-04-05T03:23:59+00:00">>},
                                               {<<"user">>,null},
                                               {<<"peer">>,<<"127.0.0.1">>},
                                               {<<"type">>,<<"generic">>}]}}]}],
                                         [[null,
                                           <<"3f5046939ff05dec5d04747d6b00640a">>],
                                          {[{<<"_id">>,
                                             <<"3f5046939ff05dec5d04747d6b00640a">>},
                                            {<<"_rev">>,
                                             <<"1-8ab18a0c2d7ddc2c8043f65ad7a79e45">>},
                                            {<<".meta">>,
                                             {[{<<"author">>,null},
                                               {<<"timestamp">>,1365117844},
                                               {<<"created_at">>,
                                                <<"2013-04-05T03:24:04+00:00">>},
                                               {<<"updated_at">>,
                                                <<"2013-04-05T03:24:04+00:00">>},
                                               {<<"user">>,null},
                                               {<<"peer">>,<<"127.0.0.1">>},
                                               {<<"type">>,<<"generic">>}]}}]}]],
                                        []],
                                       [{file,"couch_query_servers.erl"},{line,168}]},
                                      {couch_query_servers,reduce,3,
                                       [{file,"couch_query_servers.erl"},{line,138}]},
                                      {couch_mrview_util,'-open_view/5-fun-0-',4,
                                       [{file,"src/couch_mrview_util.erl"},
                                        {line,220}]},
                                      {couch_btree,'-write_node/3-lc$^0/1-0-',5,
                                       [{file,"couch_btree.erl"},{line,362}]},
                                      {couch_btree,write_node,3,
                                       [{file,"couch_btree.erl"},{line,356}]},
                                      {couch_btree,modify_node,4,
                                       [{file,"couch_btree.erl"},{line,325}]},
                                      {couch_btree,query_modify,4,
                                       [{file,"couch_btree.erl"},{line,196}]},
                                      {couch_btree,add_remove,3,
                                       [{file,"couch_btree.erl"},{line,174}]}]],
                                    []},
                                   {couch_httpd,error_info,1,
                                    [{file,"couch_httpd.erl"},{line,807}]},
                                   {couch_httpd,send_error,2,
                                    [{file,"couch_httpd.erl"},{line,912}]},
                                   {couch_httpd,handle_request_int,5,
                                    [{file,"couch_httpd.erl"},{line,365}]},
                                   {mochiweb_http,headers,5,
                                    [{file,"mochiweb_http.erl"},{line,94}]},
                                   {proc_lib,init_p_do_apply,3,
                                    [{file,"proc_lib.erl"},{line,239}]}]}},
                                {ancestors,
                                 [couch_httpd,couch_secondary_services,
                                  couch_server_sup,<0.32.0>]},
                                {messages,[]},
                                {links,[<0.103.0>,#Port<0.3508>]},
                                {dictionary,
                                 [{mochiweb_request_qs,
                                   [{"limit","11"},{"group","true"}]},
                                  {couch_rewrite_count,0},
                                  {mochiweb_request_cookie,
                                   [{"m","34e2"},
                                    {"AuthSession",
                                     "Zm9vOjUxQzlGRjJFOteZB4p-DUsezYMVnW5KtCvYh6B2"}]}]},
                                {trap_exit,false},
                                {status,running},
                                {heap_size,28690},
                                {stack_size,27},
                                {reductions,10333}],
                               []]}}
        
        Show
        Alexander Shorin added a comment - Fix issue summary and raise priority since CouchDB doesn't even returns HTTP 500 response. Just closes connection for case of invalid builtin reduce function call: CouchDB: { "couchdb" : "Welcome" , "uuid" : "df0eb380548d633a317f3b13c99c8f16" , "version" : "1.4.0+build.8d7ab8b" , "vendor" :{ "version" : "1.4.0+build.8d7ab8b" , "name" : "The Apache Software Foundation" }} ddoc: { "_id" : "_design/foo" , "_rev" : "3-f7b8e13dcaf9fbe69a63d2717fbbba16" , "language" : "javascript" , "views" : { "bar" : { "map" : "function(doc) {\n emit( null , doc);\n}" , "reduce" : "_foobar" } } } view call: curl -v http: //localhost:5984/apps/_design/foo/_view/bar * Adding handle: conn: 0x1c67fa0 * Adding handle: send: 0 * Adding handle: recv: 0 * Curl_addHandleToPipeline: length: 1 * - Conn 0 (0x1c67fa0) send_pipe: 1, recv_pipe: 0 * About to connect() to localhost port 5984 (#0) * Trying 127.0.0.1... * Connected to localhost (127.0.0.1) port 5984 (#0) > GET /apps/_design/foo/_view/bar HTTP/1.1 > User-Agent: curl/7.30.0 > Host: localhost:5984 > Accept: */* > * Empty reply from server * Connection #0 to host localhost left intact curl: (52) Empty reply from server crush log: [Tue, 25 Jun 2013 20:38:26 GMT] [info] [<0.487.0>] Starting index update for db: apps idx: _design/foo [Tue, 25 Jun 2013 20:38:26 GMT] [error] [emulator] Error in process <0.733.0> with exit value: {function_clause,[{couch_query_servers,builtin_reduce,[reduce,[<<7 bytes>>],[[[ null ,<<32 bytes>>],{[{<<3 bytes>>,<<32 bytes>>},{<<4 bytes>>,<<34 bytes>>},{<<5 bytes>>,{[{<<6 bytes>>, null },{<<9 bytes>>,1365117683},{<<10 bytes>>,<<25 bytes>>},{<<10 bytes>>,<<25 bytes>>},{<<4 bytes>>, null },{<<4 bytes>>,<<9 bytes>>},{<<4 bytes>>,<<7 bytes>>}]}}]}],[[ null ,<<32 bytes>>],{[{<<3 bytes>>,<<32 bytes>>},{<<4 bytes>>,<<34 bytes>>},{<<5 bytes>>,{[{<<6 bytes>>, null },{<<9 bytes>>,1365117839},{<<10 bytes>>,<<25 bytes>>},{<<10 bytes>>,<<25 bytes>>},{<<4 bytes>>, null },{<<4 bytes>>,<<9 bytes>>},{<<4 bytes>>,<<7 bytes>>}]}}]}],[[ null ,<<32 bytes>>],{[{<<3 bytes>>,<<32 bytes>>},{<<4 bytes>>,<<34 bytes>>},{<<5 bytes>>,{[{<<6 bytes>>, null },{<<9 bytes>>,1365117844},{<<10 bytes>>,<<25 bytes>>},{<<10 bytes>>,<<25 bytes>>},{... [Tue, 25 Jun 2013 20:38:26 GMT] [error] [<0.545.0>] {error_report,<0.31.0>, {<0.545.0>,crash_report, [[{initial_call, {mochiweb_acceptor,init, ['Argument__1','Argument__2','Argument__3']}}, {pid,<0.545.0>}, {registered_name,[]}, {error_info, {error,badarg, [{erlang,list_to_binary, [[{couch_query_servers,builtin_reduce, [reduce, [<< "_foobar" >>], [[[ null , << "3f5046939ff05dec5d04747d6b0058c6" >>], {[{<< "_id" >>, << "3f5046939ff05dec5d04747d6b0058c6" >>}, {<< "_rev" >>, << "1-93d47d1072a9b7c66c35b278eb8a9766" >>}, {<< ".meta" >>, {[{<< "author" >>, null }, {<< "timestamp" >>,1365117683}, {<< "created_at" >>, << "2013-04-05T03:21:23+00:00" >>}, {<< "updated_at" >>, << "2013-04-05T03:21:23+00:00" >>}, {<< "user" >>, null }, {<< "peer" >>,<< "127.0.0.1" >>}, {<< "type" >>,<< " generic " >>}]}}]}], [[ null , << "3f5046939ff05dec5d04747d6b0061eb" >>], {[{<< "_id" >>, << "3f5046939ff05dec5d04747d6b0061eb" >>}, {<< "_rev" >>, << "1-f6374d2b14f1e7164d596a3b030340b3" >>}, {<< ".meta" >>, {[{<< "author" >>, null }, {<< "timestamp" >>,1365117839}, {<< "created_at" >>, << "2013-04-05T03:23:59+00:00" >>}, {<< "updated_at" >>, << "2013-04-05T03:23:59+00:00" >>}, {<< "user" >>, null }, {<< "peer" >>,<< "127.0.0.1" >>}, {<< "type" >>,<< " generic " >>}]}}]}], [[ null , << "3f5046939ff05dec5d04747d6b00640a" >>], {[{<< "_id" >>, << "3f5046939ff05dec5d04747d6b00640a" >>}, {<< "_rev" >>, << "1-8ab18a0c2d7ddc2c8043f65ad7a79e45" >>}, {<< ".meta" >>, {[{<< "author" >>, null }, {<< "timestamp" >>,1365117844}, {<< "created_at" >>, << "2013-04-05T03:24:04+00:00" >>}, {<< "updated_at" >>, << "2013-04-05T03:24:04+00:00" >>}, {<< "user" >>, null }, {<< "peer" >>,<< "127.0.0.1" >>}, {<< "type" >>,<< " generic " >>}]}}]}]], []], [{file, "couch_query_servers.erl" },{line,168}]}, {couch_query_servers,reduce,3, [{file, "couch_query_servers.erl" },{line,138}]}, {couch_mrview_util,'-open_view/5-fun-0-',4, [{file, "src/couch_mrview_util.erl" }, {line,220}]}, {couch_btree,'-write_node/3-lc$^0/1-0-',5, [{file, "couch_btree.erl" },{line,362}]}, {couch_btree,write_node,3, [{file, "couch_btree.erl" },{line,356}]}, {couch_btree,modify_node,4, [{file, "couch_btree.erl" },{line,325}]}, {couch_btree,query_modify,4, [{file, "couch_btree.erl" },{line,196}]}, {couch_btree,add_remove,3, [{file, "couch_btree.erl" },{line,174}]}]], []}, {couch_httpd,error_info,1, [{file, "couch_httpd.erl" },{line,807}]}, {couch_httpd,send_error,2, [{file, "couch_httpd.erl" },{line,912}]}, {couch_httpd,handle_request_int,5, [{file, "couch_httpd.erl" },{line,365}]}, {mochiweb_http,headers,5, [{file, "mochiweb_http.erl" },{line,94}]}, {proc_lib,init_p_do_apply,3, [{file, "proc_lib.erl" },{line,239}]}]}}, {ancestors, [couch_httpd,couch_secondary_services, couch_server_sup,<0.32.0>]}, {messages,[]}, {links,[<0.103.0>,#Port<0.3508>]}, {dictionary, [{mochiweb_request_qs, [{ "limit" , "11" },{ "group" , " true " }]}, {couch_rewrite_count,0}, {mochiweb_request_cookie, [{ "m" , "34e2" }, { "AuthSession" , "Zm9vOjUxQzlGRjJFOteZB4p-DUsezYMVnW5KtCvYh6B2" }]}]}, {trap_exit, false }, {status,running}, {heap_size,28690}, {stack_size,27}, {reductions,10333}], []]}}

          People

          • Assignee:
            Unassigned
            Reporter:
            greg tappero
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:

              Development