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

DocumentChanged webhook sending incorrect revision

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.6.0
    • Fix Version/s: 2.7.0
    • Component/s: SyncGateway
    • Security Level: Public
    • Labels:
      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

            Hide
            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.

            Show
            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.
            Hide
            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.

            Show
            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.

              People

              Assignee:
              The One The One
              Reporter:
              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