weixin_39633089
weixin_39633089
2020-12-30 06:35

POST: db/_revs_diff returns 417 instead of 100

When you are using the couchbase lite database with a push replicator and you add an document to the database with the following code:

var document = _database.GetDocument("ID_MY_ID"); var properties = JsonConvert.DeserializeObject>(json); var revision = document.PutProperties(properties);

if you look at the message being sent:

POST http://../default/_revs_diff HTTP/1.1 Accept: multipart/related, application/json Content-Type: application/json Host: sdn-couchbase.cloudapp.net Content-Length: 79 Expect: 100-continue Connection: Keep-Alive

you see, that it Expects an 100-continue, the server returns an 417 however. The result is that documents with an own id are not replcated to the server.

该提问来源于开源项目:couchbase/couchbase-lite-net

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

12条回答

  • weixin_39633089 weixin_39633089 4月前

    I updated the code to no longer sent the Expect header by default.

    
    System.Net.ServicePointManager.Expect100Continue = false;
    

    and the request returns the correct message now, however documents do not get synced into cb while using an own id

    点赞 评论 复制链接分享
  • weixin_39943442 weixin_39943442 4月前

    Sorry I couldn't respond for a while. I've just arrived back in Tokyo. I'll need to involve the whole team in this discussion but in the meantime can you expand upon what you mean by "doesn't sync"? You mean your don't see activity in sync gateway? Or you do but you don't see the saved document?

    点赞 评论 复制链接分享
  • weixin_39633089 weixin_39633089 4月前

    There is a ticket created at cb support so no need for you to do that. The issue is that documents that are created in cb lite aren't pushed to the server if you use an own id. If you let cb lite generate one, it does work. I was trying to figure out why and saw this 417 error in fiddler. with the change above the error is gone, but the documents aren't being stored in the cb server.

    On Sun, Jun 7, 2015, 8:42 AM Jim Borden notifications.com wrote:

    Sorry I couldn't respond for a while. I've just arrived back in Tokyo. I'll need to involve the whole team in this discussion but in the meantime can you expand upon what you mean by "doesn't sync"? You mean your don't see activity in sync gateway? Or you do but you don't see the saved document?

    — Reply to this email directly or view it on GitHub https://github.com/couchbase/couchbase-lite-net/issues/426#issuecomment-109705221 .

    点赞 评论 复制链接分享
  • weixin_39943442 weixin_39943442 4月前

    Can you see any mention of the docs with custom ID in sync gateway logs? I'm trying to determine if the problem is happening between lite and sync gateway or between sync gateway and cb server.

    点赞 评论 复制链接分享
  • weixin_39633089 weixin_39633089 4月前

    No, there aren't any in the log of sync gateway . I have the http and http+ in the log set.

    On Sun, Jun 7, 2015, 9:27 AM Jim Borden notifications.com wrote:

    Can you see any mention of the docs with custom ID in sync gateway logs? I'm trying to determine if the problem is happening between lite and sync gateway or between sync gateway and cb server.

    — Reply to this email directly or view it on GitHub https://github.com/couchbase/couchbase-lite-net/issues/426#issuecomment-109710318 .

    点赞 评论 复制链接分享
  • weixin_39943442 weixin_39943442 4月前

    Ok I've just come up with a simple test which, for me, cannot reproduce this. So let's start to find where this simple example differs with yours.

     c#
            [Test]
            public void TestUserDefinedDocumentsGetPushed()
            {
                var document = database.GetDocument("ID_MY_ID");
                document.PutProperties(new Dictionary<string object> { { "Jim", "Borden" } });
                var push = database.CreatePushReplication(GetReplicationURL());
                RunReplication(push);
    
                StopDatabase(); //Close and delete local db
                StartDatabase();
    
                var pull = database.CreatePullReplication(GetReplicationURL());
                RunReplication(pull);
                Assert.IsNotNull(database.GetExistingDocument("ID_MY_ID"));
            }
    </string>

    This test will create a document with a custom ID, use a push replication to put it into sync gateway, delete the local DB, then use pull to get it back from sync gateway. I notice these logs inside of sync gateway:

    2015-06-07T20:31:46.810+09:00 HTTP: #004: POST /db/_bulk_docs 2015-06-07T20:31:46.811+09:00 CRUD+: Invoking sync on doc "ID_MY_ID" rev 1-be1e51e3b7dc288a3ed3a791aa9cfcf3 2015-06-07T20:31:46.855+09:00 Cache: SAVING #3 2015-06-07T20:31:46.855+09:00 CRUD: Stored doc "ID_MY_ID" / "1-be1e51e3b7dc288a3ed3a791aa9cfcf3" 2015-06-07T20:31:46.855+09:00 HTTP+: #004: --> 201 (45.2 ms) 2015-06-07T20:31:46.855+09:00 Cache: Received #3 after 0ms ("ID_MY_ID" / "1-be1e51e3b7dc288a3ed3a791aa9cfcf3") 2015-06-07T20:31:46.855+09:00 Cache: #3 ==> channel "*"

    and later

    2015-06-07T20:31:47.801+09:00 HTTP: #009: GET /db/ID_MY_ID?rev=1-be1e51e3b7dc288a3ed3a791aa9cfcf3&revs=true&attachments=true 2015-06-07T20:31:47.801+09:00 HTTP+: #009: --> 200 (0.2 ms)

    By the way this is on the latest master commit (e2e5207) and tested against both SG 1.0.4 and 1.1.0. Is there something here that is different than your workflow?

    点赞 评论 复制链接分享
  • weixin_39633089 weixin_39633089 4月前

    Yes, there is a small difference. we are using pushreplication with continuous is true. Where the replication is set during startup once.

    On Sun, Jun 7, 2015, 1:40 PM Jim Borden notifications.com wrote:

    Ok I've just come up with a simple test which, for me, cannot reproduce this. So let's start to find where this simple example differs with yours.

    
        [Test]
        public void TestUserDefinedDocumentsGetPushed()
        {
            var document = database.GetDocument("ID_MY_ID");
            document.PutProperties(new Dictionary<string object> { { "Jim", "Borden" } });
            var push = database.CreatePushReplication(GetReplicationURL());
            RunReplication(push);
    <pre><code>    StopDatabase(); //Close and delete local db
        StartDatabase();
    
        var pull = database.CreatePullReplication(GetReplicationURL());
        RunReplication(pull);
        Assert.IsNotNull(database.GetExistingDocument("ID_MY_ID"));
    }
    

    This test will create a document with a custom ID, use a push replication to put it into sync gateway, delete the local DB, then use pull to get it back from sync gateway. I notice these logs inside of sync gateway:

    2015-06-07T20:31:46.810+09:00 HTTP: #4 https://github.com/couchbase/couchbase-lite-net/issues/4: POST /db/_bulk_docs 2015-06-07T20:31:46.811+09:00 CRUD+: Invoking sync on doc "ID_MY_ID" rev 1-be1e51e3b7dc288a3ed3a791aa9cfcf3 2015-06-07T20:31:46.855+09:00 Cache: SAVING #3 https://github.com/couchbase/couchbase-lite-net/pull/3 2015-06-07T20:31:46.855+09:00 CRUD: Stored doc "ID_MY_ID" / "1-be1e51e3b7dc288a3ed3a791aa9cfcf3" 2015-06-07T20:31:46.855+09:00 HTTP+: #4 https://github.com/couchbase/couchbase-lite-net/issues/4: --> 201 (45.2 ms) 2015-06-07T20:31:46.855+09:00 Cache: Received #3 https://github.com/couchbase/couchbase-lite-net/pull/3 after 0ms ("ID_MY_ID" / "1-be1e51e3b7dc288a3ed3a791aa9cfcf3") 2015-06-07T20:31:46.855+09:00 Cache: #3 https://github.com/couchbase/couchbase-lite-net/pull/3 ==> channel "*"

    and later

    2015-06-07T20:31:47.801+09:00 HTTP: #9 https://github.com/couchbase/couchbase-lite-net/issues/9: GET /db/ID_MY_ID?rev=1-be1e51e3b7dc288a3ed3a791aa9cfcf3&revs=true&attachments=true 2015-06-07T20:31:47.801+09:00 HTTP+: #9 https://github.com/couchbase/couchbase-lite-net/issues/9: --> 200 (0.2 ms)

    By the way this is on the latest master commit (e2e5207 https://github.com/couchbase/couchbase-lite-net/commit/e2e5207baf2078a52ebcb42d56e58bbf56d961c8) and tested against both SG 1.0.4 and 1.1.0. Is there something here that is different than your workflow?

    — Reply to this email directly or view it on GitHub https://github.com/couchbase/couchbase-lite-net/issues/426#issuecomment-109741919 .

    点赞 评论 复制链接分享
  • weixin_39633089 weixin_39633089 4月前

    I will create an sample project that shows the issue and share it tomorrow with you ok?

    On Sun, Jun 7, 2015, 3:10 PM Didier Caron dgcaron.com wrote:

    Yes, there is a small difference. we are using pushreplication with continuous is true. Where the replication is set during startup once.

    On Sun, Jun 7, 2015, 1:40 PM Jim Borden notifications.com wrote:

    Ok I've just come up with a simple test which, for me, cannot reproduce this. So let's start to find where this simple example differs with yours.

    
        [Test]
        public void TestUserDefinedDocumentsGetPushed()
        {
            var document = database.GetDocument("ID_MY_ID");
            document.PutProperties(new Dictionary<string object> { { "Jim", "Borden" } });
            var push = database.CreatePushReplication(GetReplicationURL());
            RunReplication(push);
    <pre><code>    StopDatabase(); //Close and delete local db
        StartDatabase();
    
        var pull = database.CreatePullReplication(GetReplicationURL());
        RunReplication(pull);
        Assert.IsNotNull(database.GetExistingDocument("ID_MY_ID"));
    }
    

    This test will create a document with a custom ID, use a push replication to put it into sync gateway, delete the local DB, then use pull to get it back from sync gateway. I notice these logs inside of sync gateway:

    2015-06-07T20:31:46.810+09:00 HTTP: #4 https://github.com/couchbase/couchbase-lite-net/issues/4: POST /db/_bulk_docs 2015-06-07T20:31:46.811+09:00 CRUD+: Invoking sync on doc "ID_MY_ID" rev 1-be1e51e3b7dc288a3ed3a791aa9cfcf3 2015-06-07T20:31:46.855+09:00 Cache: SAVING #3 https://github.com/couchbase/couchbase-lite-net/pull/3 2015-06-07T20:31:46.855+09:00 CRUD: Stored doc "ID_MY_ID" / "1-be1e51e3b7dc288a3ed3a791aa9cfcf3" 2015-06-07T20:31:46.855+09:00 HTTP+: #4 https://github.com/couchbase/couchbase-lite-net/issues/4: --> 201 (45.2 ms) 2015-06-07T20:31:46.855+09:00 Cache: Received #3 https://github.com/couchbase/couchbase-lite-net/pull/3 after 0ms ("ID_MY_ID" / "1-be1e51e3b7dc288a3ed3a791aa9cfcf3") 2015-06-07T20:31:46.855+09:00 Cache: #3 https://github.com/couchbase/couchbase-lite-net/pull/3 ==> channel "*"

    and later

    2015-06-07T20:31:47.801+09:00 HTTP: #9 https://github.com/couchbase/couchbase-lite-net/issues/9: GET /db/ID_MY_ID?rev=1-be1e51e3b7dc288a3ed3a791aa9cfcf3&revs=true&attachments=true 2015-06-07T20:31:47.801+09:00 HTTP+: #9 https://github.com/couchbase/couchbase-lite-net/issues/9: --> 200 (0.2 ms)

    By the way this is on the latest master commit (e2e5207 https://github.com/couchbase/couchbase-lite-net/commit/e2e5207baf2078a52ebcb42d56e58bbf56d961c8) and tested against both SG 1.0.4 and 1.1.0. Is there something here that is different than your workflow?

    — Reply to this email directly or view it on GitHub https://github.com/couchbase/couchbase-lite-net/issues/426#issuecomment-109741919 .

    点赞 评论 复制链接分享
  • weixin_39943442 weixin_39943442 4月前

    Sure if you can do that it would be extremely helpful. I'll try continuous also on my end. You are running on Mono right? What version of Mono and what version of Couchbase Lite and what version of Sync Gateway?

    点赞 评论 复制链接分享
  • weixin_39633089 weixin_39633089 4月前

    Ok, i found the problem:

    i had this in my initialization code :

    
    JsonConvert.DefaultSettings = () => new JsonSerializerSettings
    {
       Formatting = Formatting.Indented,
       ContractResolver = new CamelCasePropertyNamesContractResolver()
     };
    

    if i create a document with ID = MY_ID_5259d6a3-7338-41b6-8d41-bc5d912fd057 it resulted in the following response from _revs_diff:

    
    HTTP/1.1 200 OK
    Server: Couchbase Sync Gateway/1.00
    Date: Mon, 08 Jun 2015 14:31:00 GMT
    Content-Length: 814
    Content-Type: text/plain; charset=utf-8
    
    {"mY_ID_5259d6a3-7338-41b6-8d41-bc5d912fd057":{"missing":["1-d9f29b310e3ecf9968edf0cd18a25c34"]}
    

    notice the lowercase m in the id wich is causing it to not be synced to the server. if i start with a lowercase or remove the camelcasepropertynamescontractresolver it works as expected. This explains why an autogenerated id works sometimes as they can begin with an number.

    点赞 评论 复制链接分享
  • weixin_39943442 weixin_39943442 4月前

    Interesting! So you are able to replicate without issue now? Can I close this out? Well, I'm still going to have a look into what I can do about this though. I don't want this kind of stuff to affect Couchbase Lite internally so I need to stop it from using default settings somewhere it seems.

    点赞 评论 复制链接分享
  • weixin_39775577 weixin_39775577 4月前

    Per , will refactor to not use the default settings and instead internally create our own.

    点赞 评论 复制链接分享

相关推荐