Skip to content

ArgumentNullException in TcpPackage.AsByteArray() when sending about 25 Mb at once #5

Description

@vsevolodp

First call to method

connection.AppendToStreamAsync("my-stream", -2, evts);

with events having 90000 items of average size 150 bytes leads to exception

System.ArgumentNullException was unhandled
  Message=Value cannot be null.
Parameter name: src
  Source=mscorlib
  ParamName=src
  StackTrace:
       at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
       at EventStore.ClientAPI.Defines.TcpPackage.AsByteArray() in D:\dev\lokad\sandbox\EventStore\src\EventStore\EventStore.ClientAPI\Defines\TcpPackage.cs:line 70
       at EventStore.ClientAPI.EventStoreConnection.Send(WorkItem workItem, ITaskCompletionWrapper wrapper) in D:\dev\lokad\sandbox\EventStore\src\EventStore\EventStore.ClientAPI\EventStoreConnection.cs:line 416
       at EventStore.ClientAPI.EventStoreConnection.MonitoringLoop() in D:\dev\lokad\sandbox\EventStore\src\EventStore\EventStore.ClientAPI\EventStoreConnection.cs:line 328
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

workItem.TcpPackage
{EventStore.ClientAPI.Defines.TcpPackage}
    Command: 0
    CorrelationId: {91327175-f9e1-4828-9dbe-9e3c9516bc87}
    Data: {System.ArraySegment<byte>}
workItem.TcpPackage.Data
{System.ArraySegment<byte>}
    Array: null
    Count: 0
    Offset: 0

As far as I understand client recived reply message in EventStoreConnection.OnPackageReceived and
result.Status == ProcessResultStatus.Retry, so wrapper.UpdateForNextAttempt() will be called.
WriteTaskCompletionWrapper.UpdateForNextAttempt uses SentPackage as an origin for creating new TcpPackage but SentPackage has not been initialized at this moment yet.
As a result empty message goes to EventStoreConnection._sendQueue and being poped from the queue by EventStoreConnection.MonitoringLoop method.

Adding line

taskWrapper.SentPackage = package;

after

var taskWrapper = new WriteTaskCompletionWrapper(taskCompletionSource);

in AppendToStreamAsync.EventStoreConnection solves the problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions