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 painless casting bug causing opensearch to crash #8315

Merged
merged 6 commits into from Jul 10, 2023

Conversation

shiv0408
Copy link
Member

@shiv0408 shiv0408 commented Jun 28, 2023

Description

Update

Throwing ClassCastException when trying to cast def to void.
Created a Unit Test to ensure that def to void casting throws ClassCastException. Removed the following mention Unit Test as it was just added to reproduce the issue. The current unit test should be enough to avoid any regression in future.

Created a unit test to reproduce the bug #6435 by creating a unit test. Fix for this is requires a small change in modules/lang-painless/src/main/java/org/opensearch/painless/AnalyzerCaster.java to throw ClassCastException when we are trying to cast def to void. But to create this unit test, I had to make change supported scripts in _scripts/painless/_execute API by adding the update context. How can we keep this unit test in this code without modifying the supported scripts? One option is we can keep a setting which users can't modify and set it from the test, using that setting allow the update operation in supported scripts.

Related Issues

Resolves #6435

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@dblock
Copy link
Member

dblock commented Jun 28, 2023

I had to make change supported scripts in _scripts/painless/_execute API by adding the update context

So this is a new feature? I don't know this code well, what does this do? What are the downsides? If it's new, you should make a PR adding the feature first, then another one that fixes the bug we're talking about on top, just to keep things clean.

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@shiv0408
Copy link
Member Author

So this is a new feature?

This change would allow users to run painless scripts with update context. Although, it is not my intention to add this as a new feature. Rather than creating a new feature, I wanted to keep context which is only used in tests and not by customers.

what does this do? What are the downsides?

This API allows customers to execute painless scripts with are not stored. Providing an Update context script has no major use case here.

@reta
Copy link
Collaborator

reta commented Jun 29, 2023

@shiv0408 could you please clarify what is supposed outcome of this script (from the issue):

curl -X POST "localhost:9200/hockey/_update/3?pretty" -H 'Content-Type: application/json' -d'
{
  "script": {
    "source": "def x=1;return x;",
    "lang": "painless",
    "params": {
      "sold_cost": 26
    }
  }
}
  • the sold_cost is not used - why it is there?
  • the ctx._source is not used - nothing to update?

[1] https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#update-api-example

@shiv0408
Copy link
Member Author

@reta I was modifying some script to reproduce the issue. The purpose of this script is just to demonstrate the issue, so did not use ctx._source to update any doc and param is also not required, left it by mistake.

@shiv0408
Copy link
Member Author

And I am calling this update context, but any void context like ingest or reindex can face same issue if we try to return def type in a void expecting context.

@reta
Copy link
Collaborator

reta commented Jun 30, 2023

And I am calling this update context, but any void context like ingest or reindex can face same issue if we try to return def type in a void expecting context.

So if the context is void expected - why script should return anything? And what is happening with the results that script returns? (as I see here, we just drop it)

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
@shiv0408
Copy link
Member Author

Thanks for approval @reta. Added DCO on all commits.

@reta
Copy link
Collaborator

reta commented Jul 10, 2023

@dblock looks good to you?

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: UNSTABLE ❕
  • TEST FAILURES:
      1 org.opensearch.remotestore.SegmentReplicationUsingRemoteStoreIT.testDropPrimaryDuringReplication
      1 org.opensearch.indices.replication.SegmentReplicationTargetServiceTests.testOnNewCheckpointFromNewPrimaryCancelOngoingReplication
      1 org.opensearch.indices.replication.SegmentReplicationTargetServiceTests.classMethod

@shiv0408
Copy link
Member Author

@reta Can we try to get this merged before 2.9 branch cut?

@reta
Copy link
Collaborator

reta commented Jul 10, 2023

@reta Can we try to get this merged before 2.9 branch cut?

@dblock had comments / concerns, we need his approval

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
@codecov
Copy link

codecov bot commented Jul 10, 2023

Codecov Report

Merging #8315 (c4519e0) into main (397069f) will increase coverage by 0.52%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##               main    #8315      +/-   ##
============================================
+ Coverage     70.77%   71.30%   +0.52%     
- Complexity    56893    57300     +407     
============================================
  Files          4758     4758              
  Lines        269417   269417              
  Branches      39420    39420              
============================================
+ Hits         190679   192095    +1416     
+ Misses        62635    61479    -1156     
+ Partials      16103    15843     -260     
Impacted Files Coverage Δ
...n/java/org/opensearch/painless/AnalyzerCaster.java 76.81% <100.00%> (ø)

... and 445 files with indirect coverage changes

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: UNSTABLE ❕
  • TEST FAILURES:
      1 org.opensearch.cluster.allocation.AwarenessAllocationIT.testThreeZoneOneReplicaWithForceZoneValueAndLoadAwareness

@shiv0408
Copy link
Member Author

@dblock I think it should be good to merge now.

@shiv0408 shiv0408 requested a review from dblock July 10, 2023 22:19
@dblock dblock merged commit a39f60f into opensearch-project:main Jul 10, 2023
22 checks passed
@dblock dblock added the backport 2.x Backport to 2.x branch label Jul 10, 2023
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-8315-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 a39f60f482c405a102e6eec83097e91acc90a889
# Push it to GitHub
git push --set-upstream origin backport/backport-8315-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-8315-to-2.x.

@shiv0408 shiv0408 deleted the painless-bug branch July 11, 2023 01:11
shiv0408 added a commit to shiv0408/OpenSearch that referenced this pull request Jul 11, 2023
…ect#8315)

* Created a failing test to reproduce painless bug

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed unused import

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Throw exception when trying to cast def to void

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed update context change

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Created a different test

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

---------

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
(cherry picked from commit a39f60f)
reta pushed a commit that referenced this pull request Jul 11, 2023
* Created a failing test to reproduce painless bug

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed unused import

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Throw exception when trying to cast def to void

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed update context change

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Created a different test

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

---------

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
(cherry picked from commit a39f60f)
vikasvb90 pushed a commit to raghuvanshraj/OpenSearch that referenced this pull request Jul 12, 2023
…ect#8315)

* Created a failing test to reproduce painless bug

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed unused import

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Throw exception when trying to cast def to void

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed update context change

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Created a different test

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

---------

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
raghuvanshraj pushed a commit to raghuvanshraj/OpenSearch that referenced this pull request Jul 12, 2023
…ect#8315)

* Created a failing test to reproduce painless bug

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed unused import

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Throw exception when trying to cast def to void

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed update context change

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Created a different test

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

---------

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
dzane17 pushed a commit to dzane17/OpenSearch that referenced this pull request Jul 12, 2023
…ect#8315)

* Created a failing test to reproduce painless bug

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed unused import

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Throw exception when trying to cast def to void

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed update context change

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Created a different test

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

---------

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
buddharajusahil pushed a commit to buddharajusahil/OpenSearch that referenced this pull request Jul 18, 2023
…ect#8315)

* Created a failing test to reproduce painless bug

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed unused import

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Throw exception when trying to cast def to void

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed update context change

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Created a different test

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

---------

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
Signed-off-by: sahil buddharaju <sahilbud@amazon.com>
baba-devv pushed a commit to baba-devv/OpenSearch that referenced this pull request Jul 29, 2023
…ect#8315)

* Created a failing test to reproduce painless bug

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed unused import

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Throw exception when trying to cast def to void

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed update context change

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Created a different test

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

---------

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
shiv0408 added a commit to Gaurav614/OpenSearch that referenced this pull request Apr 25, 2024
…ect#8315)

* Created a failing test to reproduce painless bug

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed unused import

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Throw exception when trying to cast def to void

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed update context change

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Created a different test

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

---------

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Opensearch process crashes when running a painless script
3 participants