Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-823

IndexOutOfRangeException during fail over with .NET SDK 2.0 .NET SDK

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.1.2
    • Component/s: library
    • Labels:
      None

      Attachments

        Issue Links

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

          Activity

          Hide
          amalraj.charles amalraj.charles added a comment -

          Hi,

          I get the below error for some document inserts not all.

          System.IndexOutOfRangeException: Index was outside the bounds of the array.
          at Couchbase.IO.Converters.AutoByteConverter.CopyAndReverse(Byte[] src, Int32 offset, Int32 length)
          at Couchbase.IO.Converters.AutoByteConverter.ToInt16(Byte[] buffer, Int32 offset)
          at Couchbase.IO.Operations.OperationBase1.Read(Byte[] buffer, Int32 offset, Int32 length)
          at Couchbase.IO.Strategies.DefaultIOStrategy.Execute[T](IOperation1 operation)
          at Couchbase.Core.Server.Send[T](IOperation`1 operation)

          This issue is not observed in SDK version 2.0.1

          Current state of cluster : Single Node Setup, Couchbase Server version 3.0.2

          Should I try it with Couchbase Server 3.0.3 ?

          If possible ill attach the code.

          Thanks,
          Amalraj

          Show
          amalraj.charles amalraj.charles added a comment - Hi, I get the below error for some document inserts not all. System.IndexOutOfRangeException: Index was outside the bounds of the array. at Couchbase.IO.Converters.AutoByteConverter.CopyAndReverse(Byte[] src, Int32 offset, Int32 length) at Couchbase.IO.Converters.AutoByteConverter.ToInt16(Byte[] buffer, Int32 offset) at Couchbase.IO.Operations.OperationBase1.Read(Byte[] buffer, Int32 offset, Int32 length) at Couchbase.IO.Strategies.DefaultIOStrategy.Execute [T] (IOperation1 operation) at Couchbase.Core.Server.Send [T] (IOperation`1 operation) This issue is not observed in SDK version 2.0.1 Current state of cluster : Single Node Setup, Couchbase Server version 3.0.2 Should I try it with Couchbase Server 3.0.3 ? If possible ill attach the code. Thanks, Amalraj
          Hide
          amalraj.charles amalraj.charles added a comment - - edited

          Json object that i am trying to Upsert is in GRAC_ROLED.txt

          Show
          amalraj.charles amalraj.charles added a comment - - edited Json object that i am trying to Upsert is in GRAC_ROLED.txt
          Hide
          amalraj.charles amalraj.charles added a comment -

          Hi was able to solve this issue by giving key as integers values instead of string (combination of different characters) .

          E.g documents with the below keys failed giving the same error as my above comment

          object_2_C_PROJ_PRC
          object_2_C_PRPS_VNR
          object_2_K_PKSA
          object_2_K_SUM_PROJ
          object_7_C_PROJ_PRC

          Looks like a bug in .NET SDK 2.0.2 and above.

          Thanks,
          Amalraj

          Show
          amalraj.charles amalraj.charles added a comment - Hi was able to solve this issue by giving key as integers values instead of string (combination of different characters) . E.g documents with the below keys failed giving the same error as my above comment object_2_C_PROJ_PRC object_2_C_PRPS_VNR object_2_K_PKSA object_2_K_SUM_PROJ object_7_C_PROJ_PRC Looks like a bug in .NET SDK 2.0.2 and above. Thanks, Amalraj
          Hide
          brettman brettman added a comment - - edited

          We are experiencing the same error under similar conditions.

          .Net client version 2.1.0

          Couchbase server:
          2 nodes running on Ubuntu
          Version: 3.0.3-1716 Enterprise Edition (build-1716)
          Cluster State ID: 025-020-213

          A few points that might be helpful:

          • Exception isn't thrown, but operation return as unsuccessful
          • Some documents consistently fail when adding
          • Changing the content of the document even slightly (usually by removing any characters) almost always results in a successful add operation for subsequent attempts
          • Even when the IndexOutOfRangeException happens, the documents appear to be saved successfully in CB (subsequent GET operations with the same ID return the expected document)

          The exception itself traces back to the Read method of OperationBase when the buffer parameter is too short. Usually 4 or 5 bytes. Seems like either the server is returning wonky data, or the buffer isn't initialized properly.

          public virtual void Read(byte[] buffer, int offset, int length)
          {
          if (Header.BodyLength == 0)
          {
          Header = new OperationHeader

          { Magic = Converter.ToByte(buffer, HeaderIndexFor.Magic), OperationCode = Converter.ToByte(buffer, HeaderIndexFor.Opcode).ToOpCode(), KeyLength = Converter.ToInt16(buffer, HeaderIndexFor.KeyLength), ExtrasLength = Converter.ToByte(buffer, HeaderIndexFor.ExtrasLength), Status = (ResponseStatus) Converter.ToInt16(buffer, HeaderIndexFor.Status), BodyLength = Converter.ToInt32(buffer, HeaderIndexFor.Body), Opaque = Converter.ToUInt32(buffer, HeaderIndexFor.Opaque), Cas = Converter.ToUInt64(buffer, HeaderIndexFor.Cas) }

          ;
          }
          LengthReceived += length;
          Data.Write(buffer, offset, length);
          }

          Show
          brettman brettman added a comment - - edited We are experiencing the same error under similar conditions. .Net client version 2.1.0 Couchbase server: 2 nodes running on Ubuntu Version: 3.0.3-1716 Enterprise Edition (build-1716) Cluster State ID: 025-020-213 A few points that might be helpful: Exception isn't thrown, but operation return as unsuccessful Some documents consistently fail when adding Changing the content of the document even slightly (usually by removing any characters) almost always results in a successful add operation for subsequent attempts Even when the IndexOutOfRangeException happens, the documents appear to be saved successfully in CB (subsequent GET operations with the same ID return the expected document) The exception itself traces back to the Read method of OperationBase when the buffer parameter is too short. Usually 4 or 5 bytes. Seems like either the server is returning wonky data, or the buffer isn't initialized properly. public virtual void Read(byte[] buffer, int offset, int length) { if (Header.BodyLength == 0) { Header = new OperationHeader { Magic = Converter.ToByte(buffer, HeaderIndexFor.Magic), OperationCode = Converter.ToByte(buffer, HeaderIndexFor.Opcode).ToOpCode(), KeyLength = Converter.ToInt16(buffer, HeaderIndexFor.KeyLength), ExtrasLength = Converter.ToByte(buffer, HeaderIndexFor.ExtrasLength), Status = (ResponseStatus) Converter.ToInt16(buffer, HeaderIndexFor.Status), BodyLength = Converter.ToInt32(buffer, HeaderIndexFor.Body), Opaque = Converter.ToUInt32(buffer, HeaderIndexFor.Opaque), Cas = Converter.ToUInt64(buffer, HeaderIndexFor.Cas) } ; } LengthReceived += length; Data.Write(buffer, offset, length); }
          Hide
          jmorris Jeff Morris added a comment - - edited

          @brettman

          Thanks for the details; would it be possible to post client logs from when this happens? I suspect I know the problem, but need more info; I am most interested in what happened before this exception is logged.

          -Jeff

          Show
          jmorris Jeff Morris added a comment - - edited @brettman Thanks for the details; would it be possible to post client logs from when this happens? I suspect I know the problem, but need more info; I am most interested in what happened before this exception is logged. -Jeff
          Hide
          buloheart buloheart added a comment -

          I'm experiencing a similar issue as well. I have prepared a test code to find out for which document size ranges it fails, as through experimenting with it, I came to the conclusion that it appears to be size related.
          So, I've run the below code to test it:

          public void TestProblematicSizes()
          {
          const int start = 0;
          const int end = 50000;
          var errorSb = new StringBuilder();
          var sb = new StringBuilder();
          for (var x = 0; x < start; ++x)
          sb.Append("+");
          var str = sb.ToString();

          for (var i = start; i < end; ++i)
          {
          str = "";
          var testClass = new TestClass

          {Id = Guid.NewGuid().ToString(), Message = str}

          ;
          try

          { _testClassRepository.Add(testClass.Id, testClass); }

          catch (Exception)

          { var len = JsonConvert.SerializeObject(testClass).Length; errorSb.AppendLine(len.ToString()); }

          }
          Debug.WriteLine(errorSb.ToString());
          }

          Also, below is from the repository object:

          public virtual bool Add(T item)
          {
          var result = Add(item.Id, item);
          return result;
          }

          public virtual bool Add(string key, T item)
          {
          using (var bucket = CouchbaseManager.Instance.OpenBucket(Bucket))
          {
          var result = bucket.Insert(new Document<T>

          { Id = key, Content = item }

          );
          if (!result.Success)
          throw new Exception(result.Message, result.Exception);

          return result.Success;
          }
          }

          The output is the numbers between 16317 - 16339, 32701 - 32723, 49085 - 49107. Three ranges, of same size, near 16k, 32k and 48k (exact same distances respectively).
          The exception we got is from the same place brettman said above.
          I hope the code above helps identify issue. Please let me know if you need more information on my end.

          Show
          buloheart buloheart added a comment - I'm experiencing a similar issue as well. I have prepared a test code to find out for which document size ranges it fails, as through experimenting with it, I came to the conclusion that it appears to be size related. So, I've run the below code to test it: public void TestProblematicSizes() { const int start = 0; const int end = 50000; var errorSb = new StringBuilder(); var sb = new StringBuilder(); for (var x = 0; x < start; ++x) sb.Append("+"); var str = sb.ToString(); for (var i = start; i < end; ++i) { str = " "; var testClass = new TestClass {Id = Guid.NewGuid().ToString(), Message = str} ; try { _testClassRepository.Add(testClass.Id, testClass); } catch (Exception) { var len = JsonConvert.SerializeObject(testClass).Length; errorSb.AppendLine(len.ToString()); } } Debug.WriteLine(errorSb.ToString()); } Also, below is from the repository object: public virtual bool Add(T item) { var result = Add(item.Id, item); return result; } public virtual bool Add(string key, T item) { using (var bucket = CouchbaseManager.Instance.OpenBucket(Bucket)) { var result = bucket.Insert(new Document<T> { Id = key, Content = item } ); if (!result.Success) throw new Exception(result.Message, result.Exception); return result.Success; } } The output is the numbers between 16317 - 16339, 32701 - 32723, 49085 - 49107. Three ranges, of same size, near 16k, 32k and 48k (exact same distances respectively). The exception we got is from the same place brettman said above. I hope the code above helps identify issue. Please let me know if you need more information on my end.
          Hide
          brettman brettman added a comment -

          Hi Jeff, thanks for the reply. In meetings today but will try to get the client logs together over the weekend.

          Show
          brettman brettman added a comment - Hi Jeff, thanks for the reply. In meetings today but will try to get the client logs together over the weekend.

            People

            • Assignee:
              jmorris Jeff Morris
              Reporter:
              jmorris Jeff Morris
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes

                  PagerDuty

                  Error rendering 'com.pagerduty.jira-server-plugin:PagerDuty'. Please contact your Jira administrators.