How to cancel a replication task via the REST API

34 views
Skip to first unread message

Nick Pomfret

unread,
Aug 3, 2016, 1:45:25 AM8/3/16
to Couchbase Mobile
I'm trying to cancel a replication task VIA the REST API.  Its not documented as far as I can see, but I gather (http://docs.couchdb.org/en/stable/api/server/common.html#post--_replicate) that I'm supposed to call the `_replicate` endpoint with the same arguments that I used to create the task, but adding a `cancel: true` parameter.  It works on Android 1.3x but not on iOS 1.3x, and I'm pretty sure that I it used to work on 1.2 in iOS (but can't be sure).

Or have I misunderstood, is there another way?


James Nocentini

unread,
Aug 3, 2016, 5:05:24 AM8/3/16
to Couchbase Mobile
The cancel: true field must be passed along with all the other properties that were specified when the replication was created (i.e. source, target, continuous etc.)


Can you share the payload of the POST /_replicate request?

James

Nick Pomfret

unread,
Aug 3, 2016, 6:52:22 AM8/3/16
to mobile-c...@googlegroups.com
Thanks for the reply.  These are the 2 calls to _replicate that start the replication tasks (sorry for the formatting):

"{\"source\":\"pc_macmini_0_c5149e0b-d6a6-4d7c-9498-ed311552c663\",\"target\":{\"headers\":{\"Cookie\":\"SyncGatewaySession=a066bb06b86bca4c71d98a8eea69ae4f3a9de400; Path=/sync_gateway; Expires=Thu, 04 Aug 2016 10:43:41 GMT\"},\"url\":\"http://192.168.1.185:4984/sync_gateway\"},\"continuous\":true}"

"{\"source\":{\"headers\":{\"Cookie\":\"SyncGatewaySession=a066bb06b86bca4c71d98a8eea69ae4f3a9de400; Path=/sync_gateway; Expires=Thu, 04 Aug 2016 10:43:41 GMT\"},\"url\":\"http://192.168.1.185:4986/sync_gateway\"},\"target\":\"pc_macmini_0_c5149e0b-d6a6-4d7c-9498-ed311552c663\",\"continuous\":true}"

And these are the 2 calls that are supposed to stop them.  They work on android 1.3x, but not on iOS - they both result in a 404.

"{\"source\":{\"headers\":{\"Cookie\":\"SyncGatewaySession=a066bb06b86bca4c71d98a8eea69ae4f3a9de400; Path=/sync_gateway; Expires=Thu, 04 Aug 2016 10:43:41 GMT\"},\"url\":\"http://192.168.1.185:4986/sync_gateway\"},\"target\":\"pc_macmini_0_c5149e0b-d6a6-4d7c-9498-ed311552c663\",\"continuous\":true,\"cancel\":true}"

"{\"source\":\"pc_macmini_0_c5149e0b-d6a6-4d7c-9498-ed311552c663\",\"target\":{\"headers\":{\"Cookie\":\"SyncGatewaySession=a066bb06b86bca4c71d98a8eea69ae4f3a9de400; Path=/sync_gateway; Expires=Thu, 04 Aug 2016 10:43:41 GMT\"},\"url\":\"http://192.168.1.185:4984/sync_gateway\"},\"continuous\":true,\"cancel\":true}"
 

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/8y3eMdlHtpM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/40f96fa0-bf0e-4758-ab28-7fb12b9cc7d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Nocentini

unread,
Aug 3, 2016, 7:12:51 AM8/3/16
to Couchbase Mobile
Hmm, I just ran the following two curl commands with iOS 1.3.0 build 50 and SG 1.3.0 build 247.

Create replication

curl -H 'Content-Type: application/json' -vX POST 'http://localhost:5984/_replicate' \

                                  -d '{"source":"untitledapp","target":{"headers":{"Cookie":"SyncGatewaySession=964dfd92221ae028c13710ab83cf4d6742ef225d; Path=/sync_gateway; Expires=2016-08-04T12:02:41.883045272+01:00"},"url":"http://localhost:4984/sync_gateway"},"continuous":true}'


Stop replication

curl -H 'Content-Type: application/json' -vX POST 'http://localhost:5984/_replicate' \
                                  -d '{"source":"untitledapp","target":{"headers":{"Cookie":"SyncGatewaySession=964dfd92221ae028c13710ab83cf4d6742ef225d; Path=/sync_gateway; Expires=2016-08-04T12:02:41.883045272+01:00"},"url":"http://localhost:4984/sync_gateway"},"continuous":true, "cancel": true}'

The response from the second request is:

{"ok":true}

Which builds of 1.3 of are you running?

James

Nick Pomfret

unread,
Aug 3, 2016, 7:16:46 AM8/3/16
to mobile-c...@googlegroups.com

Nick Pomfret

unread,
Aug 3, 2016, 7:18:01 AM8/3/16
to mobile-c...@googlegroups.com
Ah, I'm running a 1.2 sync-gateway, maybe that's the problem?  Is there a 1.3 build for OSX yet?  Can't see one in here 

James Nocentini

unread,
Aug 3, 2016, 7:25:21 AM8/3/16
to Nick Pomfret, mobile-c...@googlegroups.com
You can download couchbase-sync-gateway-community_1.3.0-274_x86_64.tar.gz in the list from that link.

Just tried with iOS build 62 and it works also.

James
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/CACfBfNtkZuDdbEZiWyuXeDkis-xW1G83WXmVQvcwv%3D-MwwsuqQ%40mail.gmail.com.

Jens Alfke

unread,
Aug 3, 2016, 11:50:29 AM8/3/16
to mobile-c...@googlegroups.com

On Aug 3, 2016, at 4:17 AM, Nick Pomfret <npom...@snowmonkey.co.uk> wrote:

Ah, I'm running a 1.2 sync-gateway, maybe that's the problem? 

Shouldn’t make a difference — canceling a replication is a purely local task that doesn’t involve the server.

FYI, the docs are here.

—Jens

Nick Pomfret

unread,
Aug 4, 2016, 5:08:32 AM8/4/16
to mobile-c...@googlegroups.com
So could someone confirm (or deny) that the cancel flag works in the latest iOS release?  I can't get it to work, but I'm sure it has worked in previous releases.

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/8y3eMdlHtpM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchbase+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/640B7A12-90AC-461F-9E9C-1E356850E89F%40couchbase.com.

James Nocentini

unread,
Aug 4, 2016, 12:29:38 PM8/4/16
to Nick Pomfret, mobile-c...@googlegroups.com
I don’t see any issue, passing cancel: true to a replication running and authenticated stops it and returns {"ok": true} in 1.3. I’ve tried with 1.2.1 and 1.3.

If there is an authentication error then /_replicate returns a 404 though (also observed in 1.2.1 and 1.3). That’s probably because it couldn’t find a replication with those parameters. A replication encountering 401 unauthorized stops immediately. We will definitely document the 404 response in the docs but I can’t reproduce what you’re encountering, can you double check and provide steps to repro if possible?

James
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/CACfBfNsLbhsD%3DM_e5pzN-cRt49JNHWMpdEeOJ4r_QX%2BqbwLL8w%40mail.gmail.com.

Jens Alfke

unread,
Aug 4, 2016, 12:30:21 PM8/4/16
to mobile-c...@googlegroups.com

On Aug 4, 2016, at 2:07 AM, Nick Pomfret <npom...@snowmonkey.co.uk> wrote:

So could someone confirm (or deny) that the cancel flag works in the latest iOS release?  I can't get it to work, but I'm sure it has worked in previous releases.

I’m pretty sure our QA functional tests make use of this. Could you file an issue, please?

—Jens

Nick Pomfret

unread,
Aug 4, 2016, 2:14:20 PM8/4/16
to mobile-c...@googlegroups.com

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/8y3eMdlHtpM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchbase+unsubscribe@googlegroups.com.

Nick Pomfret

unread,
Aug 5, 2016, 5:23:15 AM8/5/16
to mobile-c...@googlegroups.com
James - I'm pretty sure that I had it working on 1.2.1 also, but which version of 1.3 did you try?  I'm on 1.3.0-62. 

James Nocentini

unread,
Aug 5, 2016, 5:29:50 AM8/5/16
to Nick Pomfret, mobile-c...@googlegroups.com
I’m also testing with 62. Can you double check that first the replication is in /_active_tasks and has not a 401 unauthorized error. Then send the same request with cancel: true. This is the scenario you’ve describe and it’s working in my testing.

James
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/CACfBfNtzq84NrYvxQ6qOBJZABjpc_ZfNPyiDEc8z1H9PU-8HJw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages