title: BulkInsert.Store() seems to never return
body: <p>I'm using bulk-insert to "copy" docs with an id like "session/1/0000000000000000020-A" to the DB with a new Id:</p>
  
  <pre><code>                try
                  {
                      //Insert new items.
                      using (var bulkInsert = DocumentStoreHolder.Store.BulkInsert())
                      {
                          foreach (var sessionItem in storedItems)
                          {
                              var attDoc = (AttributeDoc) sessionItem;
                              if (attDoc.Value == "00000032")
                              {
                                  var x = 0; //dummy code to set a breakpoint.
                              }
  
                              sessionItem.StorageId = null; //Id is NULLED here.
                              bulkInsert.Store(sessionItem);
                          }
                      }
                  }
                  catch (Exception e)
                  {
                      Console.WriteLine(e);
                      throw;
                  }
  </code></pre>
  
  <p>I have docs with a "Value" from "00000000" to "00000050". The docs are copied until the doc with "Value=00000032" is reached. At this point </p>
  
  <pre><code>bulkInsert.Store(sessionItem)
  </code></pre>
  
  <p>seems to never return. I don't get an exception.
  In Studio I see this:</p>
  
  <p><a href="https://i.stack.imgur.com/dXQNU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dXQNU.png" alt="BulkInsert Stats"></a></p>
  
  <p>FYI: My RavenDB Id field is mapped to StorageId.</p>
  
  <pre><code>store.Conventions.FindIdentityProperty = memberInfo =&gt; memberInfo.Name == nameof(BaseDoc.StorageId);
  </code></pre>
  
  <p>I'm still trying to reproduce this with a small example...</p>
  
  <p>Version: 4.1.4-patch-41008</p>
  
  <p>Any thoughts on this?</p>
  
  <p>UPDATE:
  if I kill my application I see following exception in the log of the Raven-Studio:</p>
  
  <pre><code>failed to process bulk insert Inserted 32 documents in 11 batches. Last document id: 'AttributeDocs/160-A'
  System.InvalidOperationException: Failed to process bulk insert Inserted 32 documents in 11 batches. Last document id: 'AttributeDocs/160-A' ---&gt; Microsoft.AspNetCore.Connections.ConnectionResetException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen ---&gt; System.Net.Sockets.SocketException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen
     at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitable.GetResult()
     at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.ProcessReceives()
     at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive()
     --- End of inner exception stack trace ---
     at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
     at System.IO.Pipelines.Pipe.GetReadResult(ReadResult&amp; result)
     at System.IO.Pipelines.Pipe.GetReadAsyncResult()
     at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.PumpAsync()
     at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
     at System.IO.Pipelines.Pipe.GetReadResult(ReadResult&amp; result)
     at System.IO.Pipelines.Pipe.GetReadAsyncResult()
     at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)
     at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory`1 buffer, CancellationToken cancellationToken)
     at Raven.Client.Extensions.TaskExtensions.&lt;&gt;c__3`1.&lt;WithCancellation&gt;b__3_0(Task`1 t) in C:\Builds\RavenDB-4.1-Patch\41008\src\Raven.Client\Extensions\TaskExtensions.cs:line 36
     at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&amp; currentTaskSlot)
  --- End of stack trace from previous location where exception was thrown ---
     at Raven.Server.Documents.Handlers.BatchRequestParser.RefillParserBuffer(Stream stream, ManagedPinnedBuffer buffer, UnmanagedJsonParser parser, CancellationToken token) in C:\Builds\RavenDB-4.1-Patch\41008\src\Raven.Server\Documents\Handlers\BatchRequestParser.cs:line 965
     at Raven.Server.Documents.Handlers.BatchRequestParser.ReadMany.MoveNextUnlikely(JsonOperationContext ctx) in C:\Builds\RavenDB-4.1-Patch\41008\src\Raven.Server\Documents\Handlers\BatchRequestParser.cs:line 314
     at Raven.Server.Documents.Handlers.BulkInsertHandler.DoBulkInsert(Action`1 onProgress, CancellationToken token) in C:\Builds\RavenDB-4.1-Patch\41008\src\Raven.Server\Documents\Handlers\BulkInsertHandler.cs:line 96
     --- End of inner exception stack trace ---
     at Raven.Server.Documents.Handlers.BulkInsertHandler.DoBulkInsert(Action`1 onProgress, CancellationToken token) in C:\Builds\RavenDB-4.1-Patch\41008\src\Raven.Server\Documents\Handlers\BulkInsertHandler.cs:line 141
     at Raven.Server.Documents.Handlers.BulkInsertHandler.BulkInsert() in C:\Builds\RavenDB-4.1-Patch\41008\src\Raven.Server\Documents\Handlers\BulkInsertHandler.cs:line 28
     at Raven.Server.Routing.RequestRouter.HandlePath(RequestHandlerContext reqCtx) in C:\Builds\RavenDB-4.1-Patch\41008\src\Raven.Server\Routing\RequestRouter.cs:line 124
     at Raven.Server.RavenServerStartup.RequestHandler(HttpContext context) in C:\Builds\RavenDB-4.1-Patch\41008\src\Raven.Server\RavenServerStartup.cs:line 173
  </code></pre>
  
  <p>UPDATE 2:</p>
  
  <p>if I do <strong>not</strong> null the StorageId</p>
  
  <pre><code>sessionItem.StorageId = null; //Id is NULLED here.
  </code></pre>
  
  <p>BulkInsert works. But then the operation is pointless, of course.</p>
  
  <p><strong>Update3</strong>: </p>
  
  <p><a href="https://i.stack.imgur.com/gHPsk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gHPsk.png" alt="Call stack"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Nkr86.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nkr86.png" alt="Thread"></a></p>
  
  <p>I would guess, the client is not able to draw new HiLo numbers. If I use "someId/" every doc is stored fine.</p>
  
  <p><strong>Update 4:</strong></p>
  
  <pre><code>mscorlib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext)
  mscorlib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout)
  mscorlib.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
  mscorlib.dll!System.Threading.Tasks.Task.SpinThenBlockingWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
  mscorlib.dll!System.Threading.Tasks.Task.InternalWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
  mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task)
  Raven.Client.dll!Raven.Client.Util.AsyncHelpers.RunSync&lt;string&gt;(System.Func&lt;System.Threading.Tasks.Task&lt;string&gt;&gt; task) Line 133
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Util\AsyncHelpers.cs(133)
  Raven.Client.dll!Raven.Client.Documents.BulkInsert.BulkInsertOperation..ctor.AnonymousMethod__1(object entity) Line 214
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\BulkInsert\BulkInsertOperation.cs(214)
  Raven.Client.dll!Raven.Client.Documents.Identity.GenerateEntityIdOnTheClient.GetOrGenerateDocumentId(object entity) Line 58
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\Identity\GenerateEntityIdOnTheClient.cs(58)
  Raven.Client.dll!Raven.Client.Documents.Identity.GenerateEntityIdOnTheClient.GenerateDocumentIdForStorage(object entity) Line 83
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\Identity\GenerateEntityIdOnTheClient.cs(83)
  Raven.Client.dll!Raven.Client.Documents.BulkInsert.BulkInsertOperation.GetId(object entity) Line 490
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\BulkInsert\BulkInsertOperation.cs(490)
  Raven.Client.dll!Raven.Client.Documents.BulkInsert.BulkInsertOperation.StoreAsync(object entity, Raven.Client.Documents.Session.IMetadataDictionary metadata) Line 256
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\BulkInsert\BulkInsertOperation.cs(256)
  GrpcAkka.Server.exe!GrpcAkka.Server.Impl.SessionsImpl.SaveSession(SaveSessionRequest request, Grpc.Core.ServerCallContext context) Line 175
      at C:\Users\KingKnecht\Documents\Visual Studio 2017\Projects\GrpcAkka\GrpcAkka.Server\Impl\SessionsImpl.cs(175)
  [Resuming Async Method]
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(object stateMachine)
  mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining, ref System.Threading.Tasks.Task currentTask)
  mscorlib.dll!System.Threading.Tasks.Task.FinishContinuations()
  mscorlib.dll!System.Threading.Tasks.Task.FinishStageThree()
  mscorlib.dll!System.Threading.Tasks.Task&lt;System.__Canon&gt;.TrySetResult(System.__Canon result)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder&lt;string&gt;.SetResult(string result)
  Raven.Client.dll!Raven.Client.Documents.BulkInsert.BulkInsertOperation.StoreAsync(object entity, Raven.Client.Documents.Session.IMetadataDictionary metadata) Line 262
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\BulkInsert\BulkInsertOperation.cs(262)
  [Resuming Async Method]
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(object stateMachine)
  mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining, ref System.Threading.Tasks.Task currentTask)
  mscorlib.dll!System.Threading.Tasks.Task.FinishContinuations()
  mscorlib.dll!System.Threading.Tasks.Task.FinishStageThree()
  mscorlib.dll!System.Threading.Tasks.Task&lt;System.Threading.Tasks.VoidTaskResult&gt;.TrySetResult(System.Threading.Tasks.VoidTaskResult result)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder&lt;System.Threading.Tasks.VoidTaskResult&gt;.SetResult(System.Threading.Tasks.VoidTaskResult result)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
  Raven.Client.dll!Raven.Client.Documents.BulkInsert.BulkInsertOperation.StoreAsync(object entity, string id, Raven.Client.Documents.Session.IMetadataDictionary metadata) Line 380
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\BulkInsert\BulkInsertOperation.cs(380)
  [Resuming Async Method]
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(object stateMachine)
  mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining, ref System.Threading.Tasks.Task currentTask)
  mscorlib.dll!System.Threading.Tasks.Task.FinishContinuations()
  mscorlib.dll!System.Threading.Tasks.Task.FinishStageThree()
  mscorlib.dll!System.Threading.Tasks.Task&lt;System.Threading.Tasks.VoidTaskResult&gt;.TrySetResult(System.Threading.Tasks.VoidTaskResult result)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder&lt;System.Threading.Tasks.VoidTaskResult&gt;.SetResult(System.Threading.Tasks.VoidTaskResult result)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder&lt;System.Threading.Tasks.VoidTaskResult&gt;.SetResult(System.Threading.Tasks.Task&lt;System.Threading.Tasks.VoidTaskResult&gt; completedTask)
  Raven.Client.dll!Raven.Client.Documents.BulkInsert.BulkInsertOperation.WaitForId() Line 242
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\BulkInsert\BulkInsertOperation.cs(242)
  [Resuming Async Method]
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(object stateMachine)
  mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining, ref System.Threading.Tasks.Task currentTask)
  mscorlib.dll!System.Threading.Tasks.Task.FinishContinuations()
  mscorlib.dll!System.Threading.Tasks.Task.FinishStageThree()
  mscorlib.dll!System.Threading.Tasks.Task&lt;System.Threading.Tasks.VoidTaskResult&gt;.TrySetResult(System.Threading.Tasks.VoidTaskResult result)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder&lt;System.Threading.Tasks.VoidTaskResult&gt;.SetResult(System.Threading.Tasks.VoidTaskResult result)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
  Raven.Client.dll!Raven.Client.Http.RequestExecutor.ExecuteAsync&lt;long&gt;(Raven.Client.Http.ServerNode chosenNode, int? nodeIndex, Sparrow.Json.JsonOperationContext context, Raven.Client.Http.RavenCommand&lt;long&gt; command, bool shouldRetry, Raven.Client.Documents.Session.SessionInfo sessionInfo, System.Threading.CancellationToken token) Line 823
      at C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Http\RequestExecutor.cs(823)
  [Resuming Async Method]
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(object stateMachine)
  mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0()
  mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
  mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.ExecuteWorkItemHelper()
  mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
  mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()
  mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
  [Async Call Stack]
  [Async] Grpc.Core.dll!Grpc.Core.Internal.UnaryServerCallHandler&lt;SaveSessionRequest, SaveSessionReply&gt;.HandleCall(Grpc.Core.Internal.ServerRpcNew newRpc, Grpc.Core.Internal.CompletionQueueSafeHandle cq)
  [Async] Grpc.Core.dll!Grpc.Core.Server.HandleCallAsync(Grpc.Core.Internal.ServerRpcNew newRpc, Grpc.Core.Internal.CompletionQueueSafeHandle cq, System.Action continuation)
  </code></pre>
  
  <p><strong>UPDATE5:</strong>
  <a href="https://drive.google.com/drive/folders/1hpcqzDtCvDcdz31q5g89lDI8cpKT7d4u" rel="nofollow noreferrer">Fiddler Session</a></p>