Error saving an entity (Specified argument was out of the range of valid values) Raven 4

99 views
Skip to first unread message

Marcelo Volmaro

unread,
Jul 21, 2017, 11:03:47 AM7/21/17
to RavenDB - 2nd generation document database
In some process I'm loading an entity, doing some (async) processing and at the end, I'm simply changing one property on the entity and doing a Save. That is throwing the following ex:

ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Stack trace:
Raven.Client.Json.BlittableOperation.CompareBlittableArray(Sparrow.Json.BlittableJsonReaderArray newArray, Sparrow.Json.BlittableJsonReaderArray oldArray) @ 341
Raven.Client.Json.BlittableOperation.CompareBlittable(string id, Sparrow.Json.BlittableJsonReaderObject originalBlittable, Sparrow.Json.BlittableJsonReaderObject newBlittable, System.Collections.Generic.IDictionary<string, Raven.Client.Documents.Session.DocumentsChanges[]> changes, System.Collections.Generic.List<Raven.Client.Documents.Session.DocumentsChanges> docChanges) @ 513
Raven.Client.Json.BlittableOperation.CompareBlittable(string id, Sparrow.Json.BlittableJsonReaderObject originalBlittable, Sparrow.Json.BlittableJsonReaderObject newBlittable, System.Collections.Generic.IDictionary<string, Raven.Client.Documents.Session.DocumentsChanges[]> changes, System.Collections.Generic.List<Raven.Client.Documents.Session.DocumentsChanges> docChanges) @ 568
Raven.Client.Json.BlittableOperation.EntityChanged(Sparrow.Json.BlittableJsonReaderObject newObj, Raven.Client.Documents.Session.DocumentInfo documentInfo, System.Collections.Generic.IDictionary<string, Raven.Client.Documents.Session.DocumentsChanges[]> changes) @ 40
Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.EntityChanged(Sparrow.Json.BlittableJsonReaderObject newObj, Raven.Client.Documents.Session.DocumentInfo documentInfo, System.Collections.Generic.IDictionary<string, Raven.Client.Documents.Session.DocumentsChanges[]> changes)
Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForEntitiesPuts(Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.SaveChangesData result) @ 90
Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForSaveChanges() @ 44
Raven.Client.Documents.Session.Operations.BatchOperation.CreateRequest()
async Raven.Client.Documents.Session.AsyncDocumentSession.SaveChangesAsync(?) @ 168
async DDS.Synchronizer.Server.Repository.Store.SaveChangesAsync(?) in D:\Code\2DS\Aplicaciones\Synchronizer\DDS.Synchronizer.Server\Repository\Store_General.cs @ 60
async DDS.Synchronizer.Server.Business.AgentActions.PublishAction.Run(?) in D:\Code\2DS\Aplicaciones\Synchronizer\DDS.Synchronizer.Server\Business\AgentActions\PublishAction.cs @ 61


Please note that I can load/save that entity without problems using an UI I have to do so, and even change that very same property. This seems to be related to the time the above operation takes (usually several seconds) and that there are several async methods in between. If the operation executes almost instantly, the error doesn't happens.

This is the entity on the DB:
{
    "AdditionalConfiguration": {
        "ApplicationIdentifier": "MySQL"
    },
    "CurrentVersion": null,
    "EnvironmentId": "67212344095834112",
    "Files": {
        "Excluded": [
            "config.ini"
        ],
        "Ignored": [
            "infocompilacion.cmp",
            "config.local.ini"
        ]
    },
    "Instances": [
        {
            "InstallationPath": "d:/un/path/remoto",
            "RemoteAgentUrl": "http://localhost:5050/"
        }
    ],
    "LastUpdate": "2017-07-20T20:23:03.9489759Z",
    "Name": "Servicio",
    "SystemId": "67212334839005184",
    "Type": "Service",
    "@metadata": {
        "@collection": "ApplicationConfigurations",
        "Raven-Clr-Type": "DDS.Synchronizer.Shared.Data.ApplicationConfiguration, DDS.Synchronizer.Shared",
        "@change-vector": [
            {
                "Etag": 12140,
                "DbId": "df2c0989-0a86-4961-a3ac-1134a8691ef4"
            }
        ]
    }
}

And I'm trying to update the CurrentVersion property (that's a string).

Entity:

public class ApplicationConfiguration : INamedStorable
{
public ApplicationTypeConfiguration AdditionalConfiguration { get; set; }
public string EnvironmentId { get; set; }
public string SystemId { get; set; }
public string CurrentVersion { get; set; }
public ApplicationFiles Files { get; set; }
public ApplicationInstance[] Instances { get; set; }
public DateTime? LastUpdate { get; set; }
public string Name { get; set; }
public ApplicationType Type { get; set; }
public string Id { get; set; }
}

public sealed class ApplicationFiles
{
public string[] Excluded { get; set; }
public string[] Ignored { get; set; }
}




Oren Eini (Ayende Rahien)

unread,
Jul 21, 2017, 11:06:17 AM7/21/17
to ravendb
Are you disposing the session? 

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcelo Volmaro

unread,
Jul 21, 2017, 11:31:40 AM7/21/17
to RavenDB - 2nd generation document database
Yes, but not after the SaveChangesAsync. This is the code where I'm using this (the BusinessContext internally creates/disposes the IAsyncDocumentSession on ctor/IDisposable)

using (var context = new BusinessContext(_configuration, _logger))
{
var item = _item = _group.Items[_itemIndex];

try
{
_application = await context.Store.Applications.LoadAsync(item.ApplicationId);
_version = await context.Store.Versions.LoadAsync(item.VersionId);

var result = await PingRemoteAgent(_application);
if (!result.IsFaulted)
{
result = await PackAndSend(context);
if (!result.IsFaulted)
{
result = await StartUpdate(context);
if (!result.IsFaulted)
{

_item.Status = PublishStatus.Completed;
_item.LastMessage = "Publicación exitosa";
_application.CurrentVersion = item.VersionId;
await context.Store.Applications.SaveAsync(_application);
await context.SaveChangesAsync();
return;
}
}
}

item.Status = PublishStatus.WithErrors;
item.LastMessage = result.Errors.ToString();
}
catch (Exception e)
{
_logger.Log(LogEventType.Error, e);
item.Status = PublishStatus.WithErrors;
item.LastMessage = e.ToString();
}
}
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Jul 23, 2017, 2:04:33 AM7/23/17
to ravendb
Can you share a repro for this?
This looks like something that might happen if you disposed the session while the operation is still going.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Jul 23, 2017, 11:00:14 AM7/23/17
to RavenDB - 2nd generation document database
Unfortunately, no. While I can consistently reproduce this, this is part of a big solution with several projects that need to run all interconnected. I tried to make a small test case but I can't reproduce under the test. Also, again, this seems related to thread context switching, as I need to debug one of my projects to generate a big pause on the other end (where the error happens). If everything goes as designed, the error doesn't happens.

I already have assertions on disposed objects in my context. If the context were disposed, the "SaveChangesAsync" on my BC would had thrown (that method first asserts then calls SaveChangesAsync on the session).

Oren Eini (Ayende Rahien)

unread,
Jul 23, 2017, 3:32:35 PM7/23/17
to ravendb
I think that this happens when you are disposing _while_ you are calling SaveChangesAsync.
But I'm not sure. 
When you stop on this exception, can you check the state of the session? 

That is the only thing I can think of that would make it not repeatable.

Also, just to be sure, you aren't accessing the session from multiple threads at the same time, right?
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Jul 23, 2017, 5:40:02 PM7/23/17
to RavenDB - 2nd generation document database
Inline:


On Sunday, July 23, 2017 at 4:32:35 PM UTC-3, Oren Eini wrote:
I think that this happens when you are disposing _while_ you are calling SaveChangesAsync.

But that can only happens if I've missed an await. As you can see in the code above, that's not the case.
 
But I'm not sure. 
When you stop on this exception, can you check the state of the session? 

Sure, will try and let you know 

That is the only thing I can think of that would make it not repeatable.

Also, just to be sure, you aren't accessing the session from multiple threads at the same time, right?

That's correct. A new thread is created to execute the above code (not really a new thread, as it's run through Task.Run, so maybe it's an existing thread, but basically yes) and that code runs as a single instance/thread (again, thread may change because the nature of async, but there are not multiple threads trying to do things there...). 

Oren Eini (Ayende Rahien)

unread,
Jul 24, 2017, 1:26:15 AM7/24/17
to ravendb
In that case, I can't think of a reason why it wouldn't be 100% reproducible.
Can you check the state of the system when this happens (pause in the debugger and see what is going on elsewhere?)
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Jul 24, 2017, 9:31:32 AM7/24/17
to RavenDB - 2nd generation document database
Ok, something strange is going on here.

First SS: As you can see, the session is not disposed.
Second SS: Documents by entity (2), that's correct, one version, one application.
Thirtd SS: Here something is wrong. Inside the first item of the above array, I have TWO applications. That would be correct if I would actually had loaded two different apps, but...
Fourth SS: Second item in the applications array: Same item as the first one.

I think that for some reason Raven is thinking the Applications are two different objects and then, of course, something goes crazy.

01.png
02.png
03.png
04.png
Message has been deleted

Marcelo Volmaro

unread,
Jul 24, 2017, 12:15:08 PM7/24/17
to RavenDB - 2nd generation document database
Disregard the above post (in terms of the items)... I misread the properties/fields (my fields starts with an underscore... didn't notice the difference in casing)...

Oren Eini (Ayende Rahien)

unread,
Jul 24, 2017, 2:46:40 PM7/24/17
to ravendb
So I'm not following. Is there a lead here or not?

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


Oren Eini (Ayende Rahien)

unread,
Jul 24, 2017, 2:46:55 PM7/24/17
to ravendb
And oh, do you by any chance override equals / get hash code?

Marcelo Volmaro

unread,
Jul 24, 2017, 3:01:28 PM7/24/17
to RavenDB - 2nd generation document database
I'm not overriding anything. They are simple POCOs. And no, I don't have any leads. Check the screenshoots to see if there is anything there, or let me know what fields do you want me to check for specific states.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Jul 24, 2017, 3:11:43 PM7/24/17
to ravendb
Can we schedule a conf call tomorrow to look at this?
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Jul 24, 2017, 3:15:24 PM7/24/17
to RavenDB - 2nd generation document database
Sure, no problem. Which times are good for you?

Oren Eini (Ayende Rahien)

unread,
Jul 24, 2017, 3:45:11 PM7/24/17
to ravendb
Tomorrow, GMT+2  here.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Jul 24, 2017, 3:48:44 PM7/24/17
to RavenDB - 2nd generation document database
-3 here. It is ok for you 10am my time, 15pm your time?

Oren Eini (Ayende Rahien)

unread,
Jul 24, 2017, 3:49:34 PM7/24/17
to ravendb
Yes, that would work.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Jul 24, 2017, 4:17:03 PM7/24/17
to RavenDB - 2nd generation document database
Skype? Hangouts?

Oren Eini (Ayende Rahien)

unread,
Jul 24, 2017, 4:19:37 PM7/24/17
to ravendb
Skype is probably easiest.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Peter Balzli

unread,
Jul 25, 2017, 10:49:07 AM7/25/17
to RavenDB - 2nd generation document database
Do you have any news on this? I have very similar effects in my project with RavenDb 4. (error message / stack trace is the same)

Oren Eini (Ayende Rahien)

unread,
Jul 25, 2017, 10:54:36 AM7/25/17
to ravendb
Can you send a repro?

To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

kar...@ayende.com

unread,
Jul 25, 2017, 10:56:54 AM7/25/17
to RavenDB - 2nd generation document database
Hi Peter,

Would it possible for you to create a repo for us with this issue?

Marcelo Volmaro

unread,
Jul 27, 2017, 8:37:01 AM7/27/17
to RavenDB - 2nd generation document database
Just to close on this: I was able to send a test case and they fixed the issue. I don't know when this fix will be available, but I guess it should be in the next beta (I hope).
Reply all
Reply to author
Forward
0 new messages