Skip to content

Commit

Permalink
NCBC-932: BodyLength is zero when receive buffer tries read from it
Browse files Browse the repository at this point in the history
Motivation
----------
Fixes a bug where the receive buffer length is the size of the last send.
In certain cases when the buffer is smaller than the header size, the
first receive will fail to read the entire document.

Modifications
-------------
Before the first receive is called in Connection.Send, the buffer is reset
back to the size specified in the config.

Results
-------
Documents that exceed the buffer length by less than 24 bytes will still
properly be inserted; ResponseStatus.None will not be returned.

Change-Id: I6b9f974cea267a5ba26ee48c94be81088aed79af
Reviewed-on: http://review.couchbase.org/52692
Reviewed-by: Simon Baslé <simon@couchbase.com>
Tested-by: Jeffry Morris <jeffrymorris@gmail.com>
  • Loading branch information
jeffrymorris committed Jun 30, 2015
1 parent d8cd160 commit 5418eea
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Src/Couchbase.Tests/Core/Buckets/CouchbaseBucketTests.cs
Expand Up @@ -1674,6 +1674,17 @@ public void When_Value_Is_Null_Get_Succeeds2()
}
}

[Test]
public void When_Document_Size_Exceeds_Buffer_Length_Upsert_Succeeds()
{
using (var bucket = _cluster.OpenBucket())
{
var json = File.ReadAllText(@"Data\\bigger-than-buffer-doc.json");
var result = bucket.Upsert("XyxyUserW4thPxrmiss1onInfa-10984", json);
Assert.AreEqual(ResponseStatus.Success, result.Status);
}
}

[TestFixtureTearDown]
public void TestFixtureTearDown()
{
Expand Down
3 changes: 3 additions & 0 deletions Src/Couchbase.Tests/Couchbase.Tests.csproj
Expand Up @@ -268,6 +268,9 @@
<None Include="Data\N1QL\prepared-statement.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Data\bigger-than-buffer-doc.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions Src/Couchbase.Tests/CouchbaseBucket_Async_Tests.cs
Expand Up @@ -835,5 +835,19 @@ public async void When_Expiration_Is_2_Decremented_Key_Expires_After_2_Seconds_A
}
}
}

[Test]
public async void When_Document_Size_Exceeds_Buffer_Length_Upsert_Succeeds()
{
using (var cluster = new Cluster())
{
using (var bucket = cluster.OpenBucket())
{
var json = File.ReadAllText(@"Data\\bigger-than-buffer-doc.json");
var result = await bucket.UpsertAsync("XyxyUserW4thPxrmiss1onInfa-10984_async", json);
Assert.AreEqual(ResponseStatus.Success, result.Status);
}
}
}
}
}
1 change: 1 addition & 0 deletions Src/Couchbase.Tests/Data/bigger-than-buffer-doc.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Src/Couchbase/IO/Connection.cs
Expand Up @@ -206,6 +206,7 @@ private void Send(Socket socket, SocketAsyncEventArgs e)
}
else
{
e.SetBuffer(state.SendOffset, Configuration.BufferSize);
var willRaiseCompletedEvent = socket.ReceiveAsync(e);
if (!willRaiseCompletedEvent)
{
Expand Down

0 comments on commit 5418eea

Please sign in to comment.