RavenDB cancellation task exception when creating indexes

I'm having a problem creating indexes on RavenDB 3.5

When you create more than 3 indexes, the application simply dies, getting

Unable to connect to the remote server. Status Code: ConnectFailure

The index creation code is straightforward:

private static void CreateIndexes(IDocumentStore documentStore) { new PurchaseOrder_QueryByExternalReference().Execute(documentStore); new SupplierDocument_QueryBySupplierName().Execute(documentStore); new ProductDocument_QueryByProductIdAndName().Execute(documentStore); new PurchaseOrderLine_QueryableIndex().Execute(documentStore); new PurchaseOrderLine_ForPurchaseOrderIndex().Execute(documentStore); } 

But the same thing happens if

IndexCreation.CreateIndexes (typeof (MyIndexClass). Build, save);

Method called

. This happens with any 3 indexes from the list in any order.

The full stack trace is as follows:

exception {"The task was canceled."} Data: {System.Collections.ListDictionaryInternal} Etag: null HResult: -2146233088 HelpLink: null InnerException: null Message: "The task was canceled." Answer: {StatusCode: 503, ReasonPhrase: "Service unavailable", Version: 1.1, Contents :, Headers: {}} ResponseString: "Unable to connect to the remote server Status code: ConnectFailure" Source: "Raven.Client.Lightweight" StackTrace : "in Raven.Client.Connection.Implementation.HttpJsonRequest. <> c__DisplayClass36_0. <b__0> d.MoveNext () in C: \ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Connection \ Implementation \ HttpJsonRequest.cs : line 258 --- The end of the stack trace from the previous place where the exception was thrown --- in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification R (Task task) .Client.Connection.Implementation. HttpJsonRequest.d__38 1.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Implementation\\HttpJsonRequest.cs:line 312 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Implementation.HttpJsonRequest.<ReadResponseJsonAsync>d__35.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Implementation\\HttpJsonRequest.cs:line 221 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Async.AsyncServerClient.<>c__DisplayClass69_0.<<GetIndexAsync>b__0>d.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Async\\AsyncServerClient.cs:line 726 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.ReplicationInformerBase 1.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Implementation\\HttpJsonRequest.cs:line 312 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Implementation.HttpJsonRequest.<ReadResponseJsonAsync>d__35.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Implementation\\HttpJsonRequest.cs:line 221 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Async.AsyncServerClient.<>c__DisplayClass69_0.<<GetIndexAsync>b__0>d.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Async\\AsyncServerClient.cs:line 726 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.ReplicationInformerBase 1.d__34 1.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\ReplicationInformerBase.cs:line 417 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Raven.Client.Connection.ReplicationInformerBase 1.d__33 1.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\ReplicationInformerBase.cs:line 316 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Async.AsyncServerClient.<ExecuteWithReplication>d__164 1.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\ReplicationInformerBase.cs:line 316 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Async.AsyncServerClient.<ExecuteWithReplication>d__164 1.MoveNext () in C: \ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Connection \ Async \ AsyncServerClient.cs: line 0 - - The end of the stack trace from the previous place where the exception was thrown --- in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task task) in Raven.til.tours.tours.Utaven.Utilities.Utrances.Utaven.Utilities.Utilities.Utcies.Utilities.Utilities.Utilities.Utilities .AsyncHelpers. <> c__DisplayClass1_1 1.<<RunSync>b__0>d.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Abstractions\\Util\\AsyncHelpers.cs:line 75 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Raven.Abstractions.Util.AsyncHelpers.RunSync[T](Func 1 task) in C: \ Builds \ RavenDB- Stable-3.5 \ Raven.Abstractions \ Util \ AsyncHelpers.cs: line 89 in Raven.Client.Connection.ServerClient.GetIndex (line name) in C: \ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Connection \ ServerClient.cs: line 222 \ in Raven.Client.Indexes.AbstractIndexCreationTask.Execute (IDatabaseCommands databaseCommands, DocumentConvention documentConvention) in C: \ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Indexes \ AbstractIndexCreationTaskTask in Raven.Client.DocumentStoreBase.ExecuteIndex (AbstractIndexCreationTask indexCreationTask) in C: \ Builds \ RavenDB-Stable-3.5 \ Raven .Client.Lightweight \ DocumentStoreBase.cs: line 102 in Raven.Client.Indexes.AbstractIndexCreationTask.Execute (IDocumentStore repository) in C: \ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Indexes \ AbstractIndexCreationTask.cs: 221 in Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.CreateIndexes (IDocumentStore documentStore) in \ my \ route \ Persistence.Database.Adapter \ RavenDb \ RavenDbDocumentStoreFactory.cs: line 50 in Persistence.Database.AdapterRoreDocumentForeDocumentForeDocumentForebocument DocumentocumentStore documentStore) in \ my \ route \ Persistence.Database.Adapter \ RavenDb \ RavenDbDocumentStoreFactory.cs: line 38 in Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.Create (String ravenDbLocation, String ravenDbDatabase Pers. In my. Database.Adapter \ RavenDb \ RavenDbDocumentStoreFactory.cs: line 22 in Persistence.Database.Adapter.PersistenceAdapter. <.ctor> b__8_0 () in \ my \ route \ Persistence.Database.Adapter \ PersistenceAdapter.cs: line 53 in Persistence.Database.Adapter.PersistenceAdapter.RegisterRavenDbUtilities () in \ my \ route \ Persistence.Database.Adapter \ PersistenceAdapter .cs: ​​line 175 in Persistence.Database.Adapter.PersistenceAdapter.RegisterRavenLogic () in \ my \ route \ Persistence.Database.Adapter \ PersistenceAdapter.cs: line 86 in Persistence.Database.Adapter.PersistenceAdapter.Initialize () in \ my \ route \ Persistence.Database.Adapter \ PersistenceAdapter.cs: line 74 in My-Program.ConfigurePersistentAdapter (Settings) in \ my \ route \ MessageQueueListener \ MessageQueueListenerService.cs: line 153 in My-Program.AddBootstrapperExtension () in \ my \ route \ net-stock-purchase-service.MessageQueueListener \ MessageQueueListenerService.cs: line 118 in My-Program.Startup () in \ my \ route \ net-stock-purchase-service.MessageQueueListener \ MessageQueueListenerService.cs: string 78 "StatusCode: ServiceUnavailable TargetSite: {Void MoveNext ()}

+5
source share
3 answers

In my case, this turned out to be due to a mismatch between the ravendb client library and the installed server. The latest version of the RavenDB client was installed in my application, and version 3.0 is used on the server

0
source

When RavenDB 3.5 was released, something broke in the client package.

If you use RavenDB.Client from 3.0.30000 to 3.0.30179, then it should work.

If you use a higher version, then you will encounter (under certain conditions) this exception. To solve this problem, you can use an alternative API : store.DatabaseCommands.PutIndexes .

 var indexes = new List<AbstractIndexCreationTask>(); indexes.Add(new MyIndex1()); indexes.Add(new MyIndex2()); indexes.Add(new MyIndex....()); var transfos = new List<AbstractTransformerCreationTask>(); transfos.Add(new MyTransformer1()); transfos.Add(new MyTransformer2()); transfos.Add(new MyTransformer...()); // put indexes in 1 command var indexesToPut = IndexCreation.CreateIndexesToAdd(indexes, documentStore.Conventions); documentStore.DatabaseCommands.PutIndexes(indexesToPut); // don't forget transformers foreach (var item in transfos) { item.Execute(Store); } 

This should solve your problem.

I ran into this problem after updating my client package. Please note that the exception occurred only in console applications and not in my web applications.

+4
source

This solved the problem for me:

 var indexes = IndexCreation.CreateIndexesToAdd(new List<AbstractIndexCreationTask> {...}, store.Conventions); var alreadyExisting = store.DatabaseCommands.GetIndexes(0, 128) .ToDictionary(i => i.Name); foreach (var index in indexes.Where(i => !alreadyExisting.ContainsKey(i.Name))) store.DatabaseCommands.PutIndex(index.Name, index.Definition); store.DatabaseCommands.PutIndexes(indexes); 
+1
source

Source: https://habr.com/ru/post/1269525/


All Articles