I got this error when trying to search for some data and their RavenDB attachments, but I don't really understand what is going wrong.
System.ArgumentOutOfRangeException: Position cannot be negative, but was -4554
Parameter name: pos
This is the query I use when searching for the data
var data = (await Session.Query<MyClass>()
.Where(x => x.Workspace == CurrentWorkspace)
.Search(x => x.Number, $"*{SearchQuery}*", options: SearchOptions.And)
.OrderByDescending(x => x.CreatedAt)
.Skip(skip)
.Take(take)
.ToListAsync())
.Select(x => x.LoadAttachments<MyClass>(Session))
.Select(Mapper.Map<MyDto>);
This query is used in the search
endpoints on one of my API controllers. Most of the time the query works as expected and I get my data.
But at random times I get a 502 Bad Gateway
error on this specific endpoint and the api crashes because the dotnet process crashes. It reboots automatically and the next few request on that endpoint work normally.
I log all uncaught exceptions with Rollbar and that provided the error mentioned above and this stacktrace.
at Sparrow.Json.BlittableJsonReaderBase.ThrowInvalidPosition(System.Int32 pos) in "C:\Builds\RavenDB-Stable-4.0\src\Sparrow\Json\BlittableJsonReaderBase.cs" line 233
at Sparrow.Json.BlittableJsonReaderObject.TryGetMember(Sparrow.StringSegment name, System.Object& result) in "C:\Builds\RavenDB-Stable-4.0\src\Sparrow\Json\BlittableJsonReaderObject.cs" line 461
at Sparrow.Json.BlittableJsonReaderObject.TryGet(Sparrow.StringSegment name, T& obj) in "C:\Builds\RavenDB-Stable-4.0\src\Sparrow\Json\BlittableJsonReaderObject.cs" line 244
at Raven.Client.Documents.Session.DocumentSessionAttachmentsBase.GetNames(System.Object entity) in "C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Documents\Session\DocumentSessionAttachmentsBase.cs" line 27
at MyProject.Core.Storage.DocumentStore.DocumentStoreAttachmentExtensions.LoadAttachments(MyProject.Core.Storage.DocumentStore.IDocumentStoreAttachment instance, Raven.Client.Documents.Session.IAsyncDocumentSession session) in "/Users/dtaalbers/Work/dtaalbers/Repos D/MyProject-api/src/MyProject.Core.Storage/DocumentStore/DocumentStoreAttachmentExtensions.cs" line 10
Here is the extension that I use to fetch the RavenDB attachments:
public static T LoadAttachments<T>(this IDocumentStoreAttachment instance, IAsyncDocumentSession session)
{
var attachments = session.Advanced.Attachments.GetNames(instance).ToList();
if (attachments.Any())
{
instance.Attachments = attachments
.Where(x => !x.Name.Contains("thumb"))
.Select(x => new DocumentStoreAttachment()
{
ContentType = x.ContentType,
Hash = x.Hash,
Name = x.Name,
Size = x.Size
});
}
return (T) instance;
}
Is this something that can occur because of corrupted data in the RavenDB attachments?
Also, every time I get the 502 some logs in the event viewer of my Windows server appears.
Top error logs this:
Faulting application name: dotnet.exe, version: 2.1.26629.5, time stamp: 0x5b36971d
Faulting module name: coreclr.dll, version: 4.6.26628.5, time stamp: 0x5b356310
Exception code: 0xc0000005
Fault offset: 0x00000000001adaf7
Faulting process id: 0x12cc
Faulting application start time: 0x01d43964c4023b34
Faulting application path: C:\Program Files\dotnet\dotnet.exe
Faulting module path: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.2\coreclr.dll
Report Id: a6168db0-a617-11e8-8135-a5deffecc34e
Faulting package full name:
Faulting package-relative application ID:
Bottom error logs this;
Application: dotnet.exe
CoreCLR Version: 4.6.26628.5
Description: The process was terminated due to an internal error in the .NET Runtime at IP 00007FFD8250DAF7 (00007FFD82360000) with exit code c0000005.
I am not sure they are related but it all happens on the same API endpoint and at the same time. Sadly I can't seem to find the cause of this on my own.
Any help is appreciated!
EDIT:
I was using RavenDB server version 4.0.5
. But I upgraded it to 4.1.0-rc-41000
a few days ago. The error occurs on both versions.
User contributions licensed under CC BY-SA 3.0