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 validation of close_pit request #88702

Merged
merged 5 commits into from
Jul 22, 2022
Merged

Conversation

dnhatn
Copy link
Member

@dnhatn dnhatn commented Jul 22, 2022

ClosePointInTimeRequest#validate should return a validation error for an invalid pit_id, but it throws an IAE instead. This mistake prevents close_pit tasks of requests with empty pit_id from being removed.

I also looked at other ActionRequest#validate implementations. They do not throw exceptions.

@dnhatn dnhatn added >bug :Search/Search Search-related issues that do not fall into other categories auto-backport-and-merge v8.4.0 v7.17.6 v8.3.4 labels Jul 22, 2022
@dnhatn dnhatn requested a review from mayya-sharipova July 22, 2022 02:16
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Jul 22, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@elasticsearchmachine
Copy link
Collaborator

Hi @dnhatn, I've created a changelog YAML for you.

@ywelsch
Copy link
Contributor

ywelsch commented Jul 22, 2022

Hi Nhat. Just wondering if we can also safeguard the calling code (TransportAction) from similar mistakes in the future? Can be a separate PR

@dnhatn
Copy link
Member Author

dnhatn commented Jul 22, 2022

@ywelsch I added a safeguard, then backed it out after checking other validate implementations. I will add it back.

@dnhatn dnhatn requested a review from ywelsch July 22, 2022 12:47
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 @dnhatn!

final ActionRequestValidationException validationException;
try {
validationException = request.validate();
} catch (Exception e) {
Copy link
Contributor

@mayya-sharipova mayya-sharipova Jul 22, 2022

Choose a reason for hiding this comment

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

I am trying to understand this part of code. If assertion is always false, it means we will always throw AssertionError, right? So the code after assert false will never be executed?

Or are we checking assertions only during testing mode? And in runtime mode we don't execute assertions?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mayya-sharipova Here we fail with AssertionError in tests, but log a warning message and fail the request with an exception in production.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dnhatn Thanks for clarifying, I was also thinking the same.

Copy link
Contributor

@mayya-sharipova mayya-sharipova left a comment

Choose a reason for hiding this comment

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

@dnhatn Thanks for the fix, was also educational for me to study your changes.

@dnhatn
Copy link
Member Author

dnhatn commented Jul 22, 2022

@ywelsch @mayya-sharipova Thanks for review.

@dnhatn dnhatn merged commit a7b591b into elastic:master Jul 22, 2022
@dnhatn dnhatn deleted the validate_close_pit branch July 22, 2022 15:20
dnhatn added a commit to dnhatn/elasticsearch that referenced this pull request Jul 22, 2022
ClosePointInTimeRequest#validate should return a validation error for an 
invalid pit_id, but it throws an IAE instead. This mistake prevents
close_point_in_time tasks of requests with empty pit_id from being removed.
dnhatn added a commit to dnhatn/elasticsearch that referenced this pull request Jul 22, 2022
ClosePointInTimeRequest#validate should return a validation error for an 
invalid pit_id, but it throws an IAE instead. This mistake prevents
close_point_in_time tasks of requests with empty pit_id from being removed.
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
7.17
8.3

elasticsearchmachine pushed a commit that referenced this pull request Jul 22, 2022
ClosePointInTimeRequest#validate should return a validation error for an 
invalid pit_id, but it throws an IAE instead. This mistake prevents
close_point_in_time tasks of requests with empty pit_id from being removed.
elasticsearchmachine pushed a commit that referenced this pull request Jul 22, 2022
ClosePointInTimeRequest#validate should return a validation error for an 
invalid pit_id, but it throws an IAE instead. This mistake prevents
close_point_in_time tasks of requests with empty pit_id from being removed.
@mark-vieira mark-vieira added v8.3.3 and removed v8.3.4 labels Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.17.6 v8.3.3 v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants