Skip to content
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

Don't use Serializer context #59

Merged
merged 2 commits into from
Sep 25, 2020

Conversation

russcam
Copy link
Contributor

@russcam russcam commented Sep 22, 2020

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.

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.
@CLAassistant
Copy link

CLAassistant commented Sep 22, 2020

CLA assistant check
All committers have signed the CLA.

.gitignore Outdated Show resolved Hide resolved
@DGuidi
Copy link
Contributor

DGuidi commented Sep 22, 2020

@FObermaier have you written the JSON code or I'm wrong? can you check this?
I suspect there is problem in this code when a child "AttributesTable" object is used as a property of an "AttributesTable" parent object, but I'm pretty sure there is a test that check this and all tests are ok... so +1 for this PR for me.

@HarelM
Copy link
Contributor

HarelM commented Sep 22, 2020

See RP #36 I think it has a test with a complex attribute table which was not merged...
I would advise adding another test to use an attribute table inside an attribute table just in case...

@DGuidi
Copy link
Contributor

DGuidi commented Sep 22, 2020

@HarelM ah ok, I supposed the test was merged actually I think a similar test that verifies the bug was merged. this is precisely the bug i'm talking about

@HarelM
Copy link
Contributor

HarelM commented Sep 22, 2020

@DGuidi I couldn't find a test that serializes a table within a table, I might wrong but most test are deserializing and not serializing tests as far as I could see.
@russcam Can you add a test to your PR that serializes an attribute table that has a child attribute table?

@russcam
Copy link
Contributor Author

russcam commented Sep 22, 2020

@HarelM the changes in this PR are only to deserialization of Feature and AttributesTable, not to serialization.

@HarelM
Copy link
Contributor

HarelM commented Sep 23, 2020

@russcam my bad, you are right.
In any case, I cloned your code and added the following test:

[GeoJsonIssueNumber(59)]
        [Test]
        public void TestGeoJsonWithNestedObjectsInProperties()
        {
            const string geojson =
                @"{
    ""type"": ""Feature"",
    ""geometry"": {
      ""type"": ""Point"",
      ""coordinates"": [1, 2]
    },
    ""properties"": {
      ""complex"": {
        ""a"": [""b"", ""c""],
        ""d"": [""e"", ""f""]
      }
    } 
  }
}";

            Feature f = null;
            Assert.That(() => f = new GeoJsonReader().Read<Feature>(geojson), Throws.Nothing);
            Assert.That(f, Is.Not.Null);
            Assert.That(f.Attributes["complex"], Is.InstanceOf<AttributesTable>());
            var innerTable = f.Attributes["complex"] as AttributesTable;
            Assert.That(innerTable["a"], Is.InstanceOf<List<object>>());
            Assert.That(innerTable["d"], Is.InstanceOf<List<object>>());
        }
    }

Which passed, so it seems that this commit does not break the reading of the properties.
@FObermaier @DGuidi @airbreather Can this be merged and a new package can be created?

@DGuidi
Copy link
Contributor

DGuidi commented Sep 23, 2020

probably I made some confusion, the but we talk about it isn't directly related to @HarelM problem as far as I remember.
threading issues are related to the fact that randomly some complex attributes, like the child attributes tables, are set to the wrong object.
Hard to test (random error in a multithreaded environment, probably the hardest bug to reproduce), but I think that if we can remove the context entirely from the json codebase, we can be pretty sure the thing is fixed.
let me check asap the code if there are any other usages of the Context property.

@russcam
Copy link
Contributor Author

russcam commented Sep 23, 2020

@DGuidi I searched for Context and couldn't find any other usages, but a second pair of eyes would be good.

I think removing the use of context is a good move as it'll ensure that the Json converters will work irrespective of how JsonSerializer is constructed, whether as a singleton or a new instance per usage.

@DGuidi
Copy link
Contributor

DGuidi commented Sep 23, 2020

@russcam give a check and I've found no other usages of the context property.
so +1 for me, but I feel more comfortable waiting for a feedback from @FObermaier and @airbreather that are actually the maintainers of the project.
thanks for your contribution.

Copy link
Member

@FObermaier FObermaier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch.

@DGuidi DGuidi merged commit b6b0f60 into NetTopologySuite:develop Sep 25, 2020
@DGuidi
Copy link
Contributor

DGuidi commented Sep 25, 2020

thanks again for the contribution

@russcam
Copy link
Contributor Author

russcam commented Sep 25, 2020

No worries!

@russcam russcam deleted the dont-use-context branch October 29, 2020 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants