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

Fix MapperService StackOverflowError #23605

Merged
merged 3 commits into from
Mar 20, 2017

Conversation

jkiang13
Copy link
Contributor

@jkiang13 jkiang13 commented Mar 16, 2017

MapperService#parentTypes is rewrapped in an UnmodifiableSet in MapperService#internalMerge every time the cluster state is updated. After thousands of updates the collection is wrapped so deeply that calling a method on it generates a StackOverflowError.

I have been running this patch in my cluster to address issue #23604

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@jasontedor
Copy link
Member

Thanks for the pull request @jkiang13; can you please sign the CLA and add a test case that would fail on current master and is addressed by your patch?

@jkiang13
Copy link
Contributor Author

I did sign the CLA (perhaps I did it out of order of submitting this pull request).

I am actually not sure how to write a test case for this, as generating a StackOverflowError would kill the JVM running the test. If you look at the referenced issue I have a simple script that reproduces the issue.

@jasontedor
Copy link
Member

I am actually not sure how to write a test case for this, as generating a StackOverflowError would kill the JVM running the test.

I think that you think this because of the uncaught exception handler. It does not apply to tests, you can write a test that produces a stack overflow without killing the JVM (I did it in a recent test even). With this information, do you want to give it a try?

kOverflowError would kill the JVM running the test. If you look at the referenced issue I have a simple script that reproduces the issue.

I see it, and I appreciate, and it makes me think that you can write a test here. A script will not suffice though, it needs to be something we can run with every CI run.

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

The stored structures don't need to be put into a fresh set on every call. The proper solution here is to only wrap the structures by unmodifiable* if they changed, i.e.

if (parentTypes != this.parentTypes) {
  parentTypes = Collections.unmodifiableSet(parentTypes);
}

@ywelsch
Copy link
Contributor

ywelsch commented Mar 16, 2017

Also, the test here can simply be a unit test that does a mapping update that does not change parentTypes. The value returned by getParentTypes() should then be the same map as we had before the mapping update (reference identity).

@ywelsch
Copy link
Contributor

ywelsch commented Mar 16, 2017

bonus points if you do the same for fullPathObjectMappers.

@jkiang13 jkiang13 force-pushed the mapperservice-stackoverflow branch from 9da6d01 to 41ea6ef Compare March 17, 2017 22:26
@jkiang13 jkiang13 force-pushed the mapperservice-stackoverflow branch from 41ea6ef to f54351d Compare March 17, 2017 23:51
@jkiang13
Copy link
Contributor Author

My thought was that copying the Set always up front seemed worth it for the simplicity, especially when it looks like subtlety around these collections probably contributed to this bug arising in the first place.

But I will of course defer to you folks. Take a look at the subsequent commits.

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution.

@ywelsch ywelsch added :Search Foundations/Mapping Index mappings, including merging and defining field types >bug v5.4.0 v6.0.0-alpha1 v5.3.0 v5.2.3 labels Mar 20, 2017
@ywelsch ywelsch merged commit d010cad into elastic:master Mar 20, 2017
ywelsch pushed a commit that referenced this pull request Mar 20, 2017
MapperService#parentTypes is rewrapped in an UnmodifiableSet in MapperService#internalMerge every time the cluster state is updated. After thousands of updates the collection is wrapped so deeply that calling a method on it generates a StackOverflowError.

Closes #23604
ywelsch pushed a commit that referenced this pull request Mar 20, 2017
MapperService#parentTypes is rewrapped in an UnmodifiableSet in MapperService#internalMerge every time the cluster state is updated. After thousands of updates the collection is wrapped so deeply that calling a method on it generates a StackOverflowError.

Closes #23604
ywelsch pushed a commit that referenced this pull request Mar 20, 2017
MapperService#parentTypes is rewrapped in an UnmodifiableSet in MapperService#internalMerge every time the cluster state is updated. After thousands of updates the collection is wrapped so deeply that calling a method on it generates a StackOverflowError.

Closes #23604
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Mar 22, 2017
* master:
  Fix typo in allocation explain API docs
  Add unit tests for ReverseNestedAggregator (elastic#23651)
  Revert "Revert "Build: Upgrade min gradle to 3.3 (elastic#23544)""
  Revert "Build: Upgrade min gradle to 3.3 (elastic#23544)"
  Build: Upgrade min gradle to 3.3 (elastic#23544)
  Fix took assertion in response filter test
  Search took time should use a relative clock
  Adds toString() to snapshot operations in progress
  Docs: fix a typo in transport client's put-mapping.asciidoc (elastic#23607)
  Use include-tagged macro for high level client docs (elastic#23438)
  Update fill-column in .dir-locals.el to 100 characters
  Setup keystore during integration tests (elastic#22966)
  Fix typo 'Elastisearch' -> 'Elasticsearch' (elastic#23633)
  Comment and blank line cleanups (elastic#23647)
  docs: guidelines for students and teachers (elastic#23648)
  Fix MapperService StackOverflowError (elastic#23605)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types v5.2.3 v5.3.0 v5.4.0 v6.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants