Uploaded image for project: 'Couchbase Gateway'
  1. Couchbase Gateway
  2. CBG-522

DocumentChanged webhook sending incorrect revision

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.0
    • 2.7.0
    • SyncGateway
    • Security Level: Public
    • None

    Description

      In 2.6.0, the revisions returned by the DocumentChanged webhook were the latest revision, rather than the winning revision. This is incorrect behaviour - webhooks should never be sending conflicting, non-winning revisions.

      Steps to reproduce:

      1. Start SG with a document_changed webhook set
      2. Create a document
      3. Update the document (with branch A for example)
      4. Create a conflict from the revision in step 3 (let's say branch B)
      5. Delete the revision for branch B
      6. Observe that the webhook body sent in step 5 is actually the revision from step 3 (the now winning revision)

      2.6.0:

      2.6.0
       
       
       
      $ curl -X PUT http://localhost:4985/walrus/mydoc1 -H 'Content-Type: application/json' -d '{"test":true}'
      {"rev":"1-12ff9ce1dd501524378fe092ce9aee8f","ok":true,"id":"mydoc1"}
       
      $ curl -X PUT http://localhost:4985/walrus/mydoc1?rev=1-12ff9ce1dd501524378fe092ce9aee8f -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"A"}'
      {"id":"mydoc1","rev":"2-66258a11be0ec429274dd7070740231e","ok":true}
       
      $ curl -X PUT http://localhost:4985/walrus/mydoc1?new_edits=false -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"B","_revisions":{"start":2,"ids":["newrevid", "12ff9ce1dd501524378fe092ce9aee8f"]}}'
      {"ok":true,"id":"mydoc1","rev":"2-newrevid"}
       
      $ curl -X DELETE http://localhost:4985/walrus/mydoc1?rev=2-newrevid
      {"ok":true,"id":"mydoc1","rev":"3-64cf17340e8bb836d30a8f20376427ad"}
       
       
       
       
       
       
      $ nc -l 8000
      POST /docchanged HTTP/1.1
      Host: localhost:8000
      User-Agent: Go-http-client/1.1
      Content-Length: 72
      Content-Type: application/json
      Accept-Encoding: gzip
       
      {"_id":"mydoc1","_rev":"1-12ff9ce1dd501524378fe092ce9aee8f","test":true}^C
       
       
      $ nc -l 8000
      POST /docchanged HTTP/1.1
      Host: localhost:8000
      User-Agent: Go-http-client/1.1
      Content-Length: 96
      Content-Type: application/json
      Accept-Encoding: gzip
       
      {"_id":"mydoc1","_rev":"2-66258a11be0ec429274dd7070740231e","branch":"A","test":true,"update":1}^C
       
       
      $ nc -l 8000
      POST /docchanged HTTP/1.1
      Host: localhost:8000
      User-Agent: Go-http-client/1.1
      Content-Length: 151
      Content-Type: application/json
      Accept-Encoding: gzip
       
      {"_id":"mydoc1","_rev":"2-newrevid","_revisions":{"ids":["newrevid","12ff9ce1dd501524378fe092ce9aee8f"],"start":2},"branch":"B","test":true,"update":1}^C
       
       
      $ nc -l 8000
      POST /docchanged HTTP/1.1
      Host: localhost:8000
      User-Agent: Go-http-client/1.1
      Content-Length: 76
      Content-Type: application/json
      Accept-Encoding: gzip
       
      {"_deleted":true,"_id":"mydoc1","_rev":"3-64cf17340e8bb836d30a8f20376427ad"}
      

      h3 2.7.0:

      2.7.0
       
       
       
      $ curl -X PUT http://localhost:4985/walrus/mydoc1 -H 'Content-Type: application/json' -d '{"test":true}'
      {"rev":"1-12ff9ce1dd501524378fe092ce9aee8f","ok":true,"id":"mydoc1"}
       
      $ curl -X PUT http://localhost:4985/walrus/mydoc1?rev=1-12ff9ce1dd501524378fe092ce9aee8f -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"A"}'
      {"id":"mydoc1","rev":"2-66258a11be0ec429274dd7070740231e","ok":true}
       
      $ curl -X PUT http://localhost:4985/walrus/mydoc1?new_edits=false -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"B","_revisions":{"start":2,"ids":["newrevid", "12ff9ce1dd501524378fe092ce9aee8f"]}}'
      {"ok":true,"id":"mydoc1","rev":"2-newrevid"}
       
      $ curl -X DELETE http://localhost:4985/walrus/mydoc1?rev=2-newrevid
      {"ok":true,"id":"mydoc1","rev":"3-64cf17340e8bb836d30a8f20376427ad"}
       
       
       
       
       
       
      $ nc -l 8000
      POST /docchanged HTTP/1.1
      Host: localhost:8000
      User-Agent: Go-http-client/1.1
      Content-Length: 38
      Content-Type: application/json
      Accept-Encoding: gzip
       
      {"test":true,"_id":"mydoc1","_rev":""}^C
       
       
      $ nc -l 8000
      POST /docchanged HTTP/1.1
      Host: localhost:8000
      User-Agent: Go-http-client/1.1
      Content-Length: 62
      Content-Type: application/json
      Accept-Encoding: gzip
       
      {"branch":"A","test":true,"update":1,"_id":"mydoc1","_rev":""}^C
       
       
      $ nc -l 8000
      POST /docchanged HTTP/1.1
      Host: localhost:8000
      User-Agent: Go-http-client/1.1
      Content-Length: 62
      Content-Type: application/json
      Accept-Encoding: gzip
       
      {"test":true,"update":1,"branch":"B","_id":"mydoc1","_rev":""}^C
       
       
      $ nc -l 8000
      POST /docchanged HTTP/1.1
      Host: localhost:8000
      User-Agent: Go-http-client/1.1
      Content-Length: 137
      Content-Type: application/json
      Accept-Encoding: gzip
       
      {"branch":"A","_id":"mydoc1","_rev":"2-66258a11be0ec429274dd7070740231e","_deleted":true,"test":true,"update":1,"_id":"mydoc1","_rev":""}
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            ben.brooks Ben Brooks created issue -
            ben.brooks Ben Brooks made changes -
            Field Original Value New Value
            Link This issue causes CBG-521 [ CBG-521 ]
            adamf Adam Fraser added a comment -

            I don't think the 2.6.0 behaviour is correct. I'd expect the webhook notifications to reflect the current winning revision, not the last updated non-winning revision. (i.e. I'd expect it to match the pattern used for a _changes stream).

            Given that we didn't have test coverage, it's also possible this hasn't been consistent in previous versions.

            adamf Adam Fraser added a comment - I don't think the 2.6.0 behaviour is correct. I'd expect the webhook notifications to reflect the current winning revision, not the last updated non-winning revision. (i.e. I'd expect it to match the pattern used for a _changes stream). Given that we didn't have test coverage, it's also possible this hasn't been consistent in previous versions.
            adamf Adam Fraser made changes -
            Resolution Not a Bug [ 10200 ]
            Status Open [ 1 ] Resolved [ 5 ]
            adamf Adam Fraser made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            adamf Adam Fraser made changes -
            Resolution Not a Bug [ 10200 ]
            Status Closed [ 6 ] Reopened [ 4 ]
            adamf Adam Fraser made changes -
            Affects Version/s 2.6.0 [ 15420 ]
            Affects Version/s Mercury [ 15421 ]
            adamf Adam Fraser made changes -
            Description The revisions returned by the DocumentChanged webhook seem to be coming from the winning revision, rather than the changed revision. In 2.6.0 these were always the revision that changed.
            h3. Steps to reproduce:
             # Start SG with a document_changed webhook set
             # Create a document
             # Update the document (with branch A for example)
             # Create a conflict from the revision in step 3 (let's say branch B)
             # Delete the revision for branch B
             # Observe that the webhook body sent in step 5 is actually the revision from step 3 (the now winning revision)

            h3. 2.6.0:
            {code}2.6.0



            $ curl -X PUT http://localhost:4985/walrus/mydoc1 -H 'Content-Type: application/json' -d '{"test":true}'
            {"rev":"1-12ff9ce1dd501524378fe092ce9aee8f","ok":true,"id":"mydoc1"}

            $ curl -X PUT http://localhost:4985/walrus/mydoc1?rev=1-12ff9ce1dd501524378fe092ce9aee8f -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"A"}'
            {"id":"mydoc1","rev":"2-66258a11be0ec429274dd7070740231e","ok":true}

            $ curl -X PUT http://localhost:4985/walrus/mydoc1?new_edits=false -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"B","_revisions":{"start":2,"ids":["newrevid", "12ff9ce1dd501524378fe092ce9aee8f"]}}'
            {"ok":true,"id":"mydoc1","rev":"2-newrevid"}

            $ curl -X DELETE http://localhost:4985/walrus/mydoc1?rev=2-newrevid
            {"ok":true,"id":"mydoc1","rev":"3-64cf17340e8bb836d30a8f20376427ad"}






            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 72
            Content-Type: application/json
            Accept-Encoding: gzip

            {"_id":"mydoc1","_rev":"1-12ff9ce1dd501524378fe092ce9aee8f","test":true}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 96
            Content-Type: application/json
            Accept-Encoding: gzip

            {"_id":"mydoc1","_rev":"2-66258a11be0ec429274dd7070740231e","branch":"A","test":true,"update":1}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 151
            Content-Type: application/json
            Accept-Encoding: gzip

            {"_id":"mydoc1","_rev":"2-newrevid","_revisions":{"ids":["newrevid","12ff9ce1dd501524378fe092ce9aee8f"],"start":2},"branch":"B","test":true,"update":1}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 76
            Content-Type: application/json
            Accept-Encoding: gzip

            {"_deleted":true,"_id":"mydoc1","_rev":"3-64cf17340e8bb836d30a8f20376427ad"}
            {code}
            h3 2.7.0:
            {code}2.7.0



            $ curl -X PUT http://localhost:4985/walrus/mydoc1 -H 'Content-Type: application/json' -d '{"test":true}'
            {"rev":"1-12ff9ce1dd501524378fe092ce9aee8f","ok":true,"id":"mydoc1"}

            $ curl -X PUT http://localhost:4985/walrus/mydoc1?rev=1-12ff9ce1dd501524378fe092ce9aee8f -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"A"}'
            {"id":"mydoc1","rev":"2-66258a11be0ec429274dd7070740231e","ok":true}

            $ curl -X PUT http://localhost:4985/walrus/mydoc1?new_edits=false -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"B","_revisions":{"start":2,"ids":["newrevid", "12ff9ce1dd501524378fe092ce9aee8f"]}}'
            {"ok":true,"id":"mydoc1","rev":"2-newrevid"}

            $ curl -X DELETE http://localhost:4985/walrus/mydoc1?rev=2-newrevid
            {"ok":true,"id":"mydoc1","rev":"3-64cf17340e8bb836d30a8f20376427ad"}






            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 38
            Content-Type: application/json
            Accept-Encoding: gzip

            {"test":true,"_id":"mydoc1","_rev":""}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 62
            Content-Type: application/json
            Accept-Encoding: gzip

            {"branch":"A","test":true,"update":1,"_id":"mydoc1","_rev":""}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 62
            Content-Type: application/json
            Accept-Encoding: gzip

            {"test":true,"update":1,"branch":"B","_id":"mydoc1","_rev":""}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 137
            Content-Type: application/json
            Accept-Encoding: gzip

            {"branch":"A","_id":"mydoc1","_rev":"2-66258a11be0ec429274dd7070740231e","_deleted":true,"test":true,"update":1,"_id":"mydoc1","_rev":""}
            {code}
            In 2.6.0, the revisions returned by the DocumentChanged webhook were the latest revision, rather than the winning revision. This is incorrect behaviour - webhooks should never be sending conflicting, non-winning revisions.

            h3. Steps to reproduce:
             # Start SG with a document_changed webhook set
             # Create a document
             # Update the document (with branch A for example)
             # Create a conflict from the revision in step 3 (let's say branch B)
             # Delete the revision for branch B
             # Observe that the webhook body sent in step 5 is actually the revision from step 3 (the now winning revision)

            h3. 2.6.0:
            {code}2.6.0



            $ curl -X PUT http://localhost:4985/walrus/mydoc1 -H 'Content-Type: application/json' -d '{"test":true}'
            {"rev":"1-12ff9ce1dd501524378fe092ce9aee8f","ok":true,"id":"mydoc1"}

            $ curl -X PUT http://localhost:4985/walrus/mydoc1?rev=1-12ff9ce1dd501524378fe092ce9aee8f -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"A"}'
            {"id":"mydoc1","rev":"2-66258a11be0ec429274dd7070740231e","ok":true}

            $ curl -X PUT http://localhost:4985/walrus/mydoc1?new_edits=false -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"B","_revisions":{"start":2,"ids":["newrevid", "12ff9ce1dd501524378fe092ce9aee8f"]}}'
            {"ok":true,"id":"mydoc1","rev":"2-newrevid"}

            $ curl -X DELETE http://localhost:4985/walrus/mydoc1?rev=2-newrevid
            {"ok":true,"id":"mydoc1","rev":"3-64cf17340e8bb836d30a8f20376427ad"}






            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 72
            Content-Type: application/json
            Accept-Encoding: gzip

            {"_id":"mydoc1","_rev":"1-12ff9ce1dd501524378fe092ce9aee8f","test":true}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 96
            Content-Type: application/json
            Accept-Encoding: gzip

            {"_id":"mydoc1","_rev":"2-66258a11be0ec429274dd7070740231e","branch":"A","test":true,"update":1}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 151
            Content-Type: application/json
            Accept-Encoding: gzip

            {"_id":"mydoc1","_rev":"2-newrevid","_revisions":{"ids":["newrevid","12ff9ce1dd501524378fe092ce9aee8f"],"start":2},"branch":"B","test":true,"update":1}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 76
            Content-Type: application/json
            Accept-Encoding: gzip

            {"_deleted":true,"_id":"mydoc1","_rev":"3-64cf17340e8bb836d30a8f20376427ad"}
            {code}
            h3 2.7.0:
            {code}2.7.0



            $ curl -X PUT http://localhost:4985/walrus/mydoc1 -H 'Content-Type: application/json' -d '{"test":true}'
            {"rev":"1-12ff9ce1dd501524378fe092ce9aee8f","ok":true,"id":"mydoc1"}

            $ curl -X PUT http://localhost:4985/walrus/mydoc1?rev=1-12ff9ce1dd501524378fe092ce9aee8f -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"A"}'
            {"id":"mydoc1","rev":"2-66258a11be0ec429274dd7070740231e","ok":true}

            $ curl -X PUT http://localhost:4985/walrus/mydoc1?new_edits=false -H 'Content-Type: application/json' -d '{"test":true,"update":1,"branch":"B","_revisions":{"start":2,"ids":["newrevid", "12ff9ce1dd501524378fe092ce9aee8f"]}}'
            {"ok":true,"id":"mydoc1","rev":"2-newrevid"}

            $ curl -X DELETE http://localhost:4985/walrus/mydoc1?rev=2-newrevid
            {"ok":true,"id":"mydoc1","rev":"3-64cf17340e8bb836d30a8f20376427ad"}






            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 38
            Content-Type: application/json
            Accept-Encoding: gzip

            {"test":true,"_id":"mydoc1","_rev":""}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 62
            Content-Type: application/json
            Accept-Encoding: gzip

            {"branch":"A","test":true,"update":1,"_id":"mydoc1","_rev":""}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 62
            Content-Type: application/json
            Accept-Encoding: gzip

            {"test":true,"update":1,"branch":"B","_id":"mydoc1","_rev":""}^C


            $ nc -l 8000
            POST /docchanged HTTP/1.1
            Host: localhost:8000
            User-Agent: Go-http-client/1.1
            Content-Length: 137
            Content-Type: application/json
            Accept-Encoding: gzip

            {"branch":"A","_id":"mydoc1","_rev":"2-66258a11be0ec429274dd7070740231e","_deleted":true,"test":true,"update":1,"_id":"mydoc1","_rev":""}
            {code}
            adamf Adam Fraser added a comment -

            Updating this issue to clarify that this was a bug in 2.6.0 that is addressed by the new handling in 2.7.0.

            adamf Adam Fraser added a comment - Updating this issue to clarify that this was a bug in 2.6.0 that is addressed by the new handling in 2.7.0.
            adamf Adam Fraser made changes -
            Resolution Fixed [ 1 ]
            Status Reopened [ 4 ] Resolved [ 5 ]
            ben.brooks Ben Brooks made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

            People

              The One The One
              ben.brooks Ben Brooks
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty