Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-3388

queryserver protocol violation - add_fun used incorrectly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • None
    • None
    • Database Core
    • None

    Description

      In relation COUCHDB-3387, there is another serious issue with the query server protocol violation.

      Just look into the following log:

      [debug] 2017-04-21T06:48:46.000000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Input  :: ["reset",{"reduce_limit":true,"timeout":5000}]
      [debug] 2017-04-21T06:48:46.001000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Output :: true
      [debug] 2017-04-21T06:48:46.001000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Input  :: ["add_fun","function(doc) {emit(doc._id,doc._rev);}"]
      [debug] 2017-04-21T06:48:46.003000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Output :: true
      [debug] 2017-04-21T06:48:46.004000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Input  :: ["add_fun","function(keys,values,rereduce) {if (rereduce) return sum(values); else return values.length;}"]
      [debug] 2017-04-21T06:48:46.007000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Output :: true
      

      As you can see, the third input line sends reduce function to add_fun. This is against the rules. According to the documentation:
      (http://docs.couchdb.org/en/2.0.0/query-server/protocol.html#add-fun), the argument of this command is: Map function source code..

      Why is it called with a reduce function ?

      I can guess the reason. The couchDb core uses queryserver's add_fun to check, whether the string contains a valid function. This is not ordinary bug in code, this is very bad decision which may result to a lot of confusions.

      I suggest to use the "ddoc/new" command instead the "add_fun" (http://docs.couchdb.org/en/2.0.0/query-server/protocol.html#ddoc) to check whether the design document is valid. The query server can eventually validate every function in it including the shared code ("lib" section).

      This is the serious bug for me now. Fixing this bug also resolves COUCHDB-3387 issue. However, leaving this unfixed prevents me to upgrade to the CouchDB 2.0.

      Ondřej Novak

      Attachments

        Activity

          People

            Unassigned Unassigned
            bredy Ondřej Novák
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: