-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deserialization in parallel causes invalid objects #4791
Comments
I've checked a bit the code and looks to me (but probably I'm wrong) that ConnectionSettingsAwareSerializerBase initialize a list of json converters that uses during deserialization process. |
See my commit here to fix this issue: |
Hi @HarelM, Please note that NEST 5.x is no longer supported, so we are no longer pushing out new releases of 5.x. Can you replicate the issue in 6.x or 7.x, which are supported? |
Thanks for getting back to me! Since this issue doesn't always reproduce, and it reproduced mainly on my production environment I wouldn't like to try and reproduce it on later versions there. Having said that, I could use your help in migrating to later version of elastic in my dev environment and see if I can reproduce it there. I followed the migration documents but was unable to get the results I did with 5.x. If you can direct me to other documents explaining how to easily migrate indices that were created in old versions it would be great as I haven't found such a document (the documents mainly describe which version are backwards compatible and not how to easily migrate and index). |
I'm not 100% sure that this bug is coming from the client; it sounds like it originates from a There are quite a few serialization changes between 5.x, 6.x and 7.x:
so it's possible that you may not see the same behaviour even just in upgrading the client.
Take a look at the upgrading Elasticsearch documentation that has a table of the recommended upgrade paths from 5.x to 7.8.0. On Elasticsearch 5.6.3, you should be able to do a rolling upgrade to 6.8, then a rolling upgrade from 6.8 to 7.8.0. Going to 6.8 as an intermediate step will update indices.
This might be related to the move to using BKD tree data structure for geo_shapes. I think the gaps in moving to BKD trees have now been closed in Elasticsearch 7.7.0+, e.g. |
Unfortunately, I can't seem to be able to create a small reproducible example as mentioned in the NTS thread as the cause of the issue seems to be timing and multi threading, and it doesn't happen all the time, it happens sometimes, which is the worst kind of bugs. I was able to reproduce it on my dev env for a short while but then it stopped happening without me changing any code... You and @DGuidi seem to think the bug is no in your code but in the other party's, which is unfortunate as the bug exists and no one want to take care of it. :-( While there were changes in later versions of NEST the fact is that It might not be the right solution, but moving from storing the serializer(s) to storing only the settings/options object and creating a serializer every time the As to upgrading, I followed the instructions there and failed like a noob. I also did a migration to docker at the same time, so I might have had too much noise. |
@HarelM Stating that no one wants to take care of it is a mischaracterisation. At the moment, there is not a clear reproducible example to demonstrate the issue, requiring an investment in time and effort to come up with one and investigate. In addition, the issue is for a version no longer supported and it's not clear that the issue is with the client. This is why I think a minimal reproducible example is so important; it removes all extraneous variables, reducing the problem space to one that can expedite investigation 😃
Json.NET's elasticsearch-net/src/Nest/CommonAbstractions/ConnectionSettings/ConnectionSettingsBase.cs Lines 100 to 101 in 641df53
which may break the assumptions that the usage of |
It's hard to understand, at least for me, how the elastic code uses the json serializers during the deserialization process. It's also hard to talk about "a bug", maybe there is some assumptions involved. |
Thank you both for your fast responses. :-) It might be solved in latest version and it might not be, I don't know and I don't want to find it the hard way when deploying to server). I would try and take my findings and see if you can reproduce it in 5.6 and if so see if you can upgrade to 7.8 and make sure this is resolved. I'm not an expert with ES and so I think that you (@russcam) should be able to do it better than I do... I'd be happy to provide all the required data and help to try and reproduce it. |
I did not, I'm not sure how to as I'm not deriving from |
Hi @HarelM I noticed in your linked ticket you are getting close to upgrading Elasticsearch and the client, we would be very keen to hear if the problem persists although I suspect not. Since we moved away from Json.NET as default serializer and you rely on This will use I saw that the fix you did to call Our So this might resurface the issue your facing. I went hunting a bit and wonder if these thread safety issues on JamesNK/Newtonsoft.Json#1393 The referenceresolver bug might explain the duplication. If benchmarking using |
@Mpdreamz thanks for taking the time to review this issue and what I wrote. |
On the client side we offer versioned packages: https://www.elastic.co/blog/nest-and-elasticsearch-net-upgrading-your-codebase To aid with the upgrade period where both versions exists, though still a non trivial excercise. Long term Elasticsearch server will introduce API versioning to mitigate this issue: elastic/elasticsearch#51816 (comment) (which will allow 7.x clients to talk to 8.x). See also @russcam's commment here: #4967 (comment) |
The server was updated with version 7.9.1. The upgrade experience was a nightmare and I ended up shutting down the site for several hours using elasticdump and not all the complex stuff offered by elastic as they were too confusing and hard to follow. |
Sorry to disappoint, the issue exists in 7.9.1 as well. I have just seen it in the logs :-( |
Speaking out of turn because it was @russcam who noticed this but Which on initial quick scan could explain concurrency/reuse issues. This would explain why creating a new |
@DGuidi any chance you can take a look at it? |
@HarelM and all, indeed GeoJSON serializer uses to deserialize features. |
@DGuidi can you please explain why using the same serializer instance from multiple threads at the same time is considered incorrect? |
simply speaking, context is used to keep track of which feature is currently deserialized, so proper "complex attributes" (like a table or a child object used as a field of a parent object) can be assigned. Using the same deserializer from different threads at the same can assign child objects to te wrong parent. |
Relates:elastic/elasticsearch-net#4791 This commit updates the AttributesTableConverter and FeatureConverter to not use the serializer context when deserializing AttributesTable. The serializer context is not safe to use multithreaded, which can be the case when JsonConverters from NetTopologySuite.IO.GeoJson are added to an singleton instance of JsonSerializer not under the control of NetTopologySuite.IO.GeoJson.
I've opened NetTopologySuite/NetTopologySuite.IO.GeoJSON#59 to remove the use of serializer context; its usage isn't integral to NetTopologySuite's deserialization approach, and can be rewritten to not use it. |
NetTopologySuite.IO.GeoJSON v2.0.4 includes this fix. |
@airbreather Thanks! I'll update the package, remove my workaround and report back here. |
I have updated the server with the package, removed my workaround and looks like this issue is resolved. |
Great to hear that the issue is now resolved, @HarelM. Closing this issue. |
NEST/Elasticsearch.Net version: 5.6.6
Elasticsearch version: 5.6.3
Description of the problem including expected versus actual behavior:
Actual:
When deserializing a GeoJson object using NTS the
properties
data is duplicated from one entity to the other.Expected: Data should not "leak".
Steps to reproduce:
search
in parallelIt doesn't happen all the time, it happens from time to time which I believe is related to timing and multithread stuff...
Code can be seen here:
https://github.com/IsraelHikingMap/Site/blob/master/IsraelHiking.DataAccess/ElasticSearchGateway.cs#L381L401
Expected behavior
There shouldn't be a "memory override"
Provide
ConnectionSettings
(if relevant):https://github.com/IsraelHikingMap/Site/blob/master/IsraelHiking.DataAccess/ElasticSearchGateway.cs#L66L75
Most of the info can be found in the following thread, I don't know if the problem is here or in the deserialization code in the NTS library... :-(
The comment below and afterwards is the relevant discussion.
There are also elastic dump there.
NetTopologySuite/NetTopologySuite.IO.GeoJSON#46 (comment)
Provide
DebugInformation
(if relevant):Can be found in the above issue.
Any help would be greatly appreciated. Running on .net core 3.1 windows server 2012 R2.
The text was updated successfully, but these errors were encountered: