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

[chore] Fix unhandled exceptions thrown by stoi #48965

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Tech-Circle-48
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #48859

Problem Summary:
fixes the issue where providing a timeout value exceeding the range of int32 causes a core dump during streamload.

The root cause is that the timeout value parsed using std::stoi() can throw a std::out_of_range exception if the value exceeds int32 limits, which wasn't handled correctly.

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen
Copy link
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@@ -337,6 +337,8 @@ Status StreamLoadAction::_on_header(HttpRequest* http_req, std::shared_ptr<Strea
ctx->timeout_second = std::stoi(http_req->header(HTTP_TIMEOUT));
} catch (const std::invalid_argument& e) {
return Status::InvalidArgument("Invalid timeout format, {}", e.what());
} catch (const std::out_of_range& e) {
Copy link
Contributor

@sollhui sollhui Mar 12, 2025

Choose a reason for hiding this comment

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

Please add regression test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

run buildall

@@ -157,7 +157,7 @@ class StreamLoadContext {
// optional
std::string sub_label;
double max_filter_ratio = 0.0;
int32_t timeout_second = -1;
int64_t timeout_second = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to change this type.

@@ -337,6 +337,8 @@ Status StreamLoadAction::_on_header(HttpRequest* http_req, std::shared_ptr<Strea
ctx->timeout_second = std::stoi(http_req->header(HTTP_TIMEOUT));
} catch (const std::invalid_argument& e) {
return Status::InvalidArgument("Invalid timeout format, {}", e.what());
} catch (const std::out_of_range& e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also fix other places that use the stoi function together.

@Tech-Circle-48
Copy link
Contributor Author

run buildall

LOG(WARNING) << fmt::format("Invalid shard_id format: {}, error: {}", _shards, e.what());
} catch (std::out_of_range& e) {
LOG(WARNING) << fmt::format("Shard_id value out of range: {}, error: {}", _shards,
e.what());
Copy link
Contributor

Choose a reason for hiding this comment

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

set shard_id = -1 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

} catch (std::invalid_argument&) {
LOG(WARNING) << "Invalid cluster_id value: " << content;
} catch (std::out_of_range&) {
LOG(WARNING) << "cluster_id value out of range: " << content;
Copy link
Contributor

Choose a reason for hiding this comment

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

just return an errror.

<< ", error: " << e.what();
} catch (const std::out_of_range& e) {
LOG(WARNING) << "ignore_above value out of range: "
<< ",error: " << e.what();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should return an error.

} catch (const std::invalid_argument& e) {
LOG(WARNING) << "Invalid expiration value format in dir_name: " << dir_name
<< ",error: " << e.what();
actual_expire = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

do not set it to zero.

Copy link
Contributor

@gavinchou gavinchou Mar 18, 2025

Choose a reason for hiding this comment

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

why this cpp file is in regression-test folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

already remove

return;
}
} catch (const std::invalid_argument& e) {
LOG(WARNING) << "Invalid idx format: " << s.obj_info().id()
Copy link
Contributor

Choose a reason for hiding this comment

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

do error handling as line 2782 does when we meet exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's been modified

@gavinchou gavinchou changed the title [fix](streamload) Fix streamload timeout out-of-range issue casing coredump [chore] Fix unhandled exceptions thrown by stoi Mar 18, 2025
<< ", error: " << e.what();
return;
} catch (const std::out_of_range& e) {
LOG(WARNING) << "Idx value out of range: " << s.obj_info().id()
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's been modified

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 18.36% (38/207) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 48.88% (13092/26784)
Line Coverage 38.44% (112880/293689)
Region Coverage 37.26% (57411/154099)
Branch Coverage 32.34% (28837/89166)

_ignore_above = std::stoi(ignore_above_value);
} catch (const std::invalid_argument& e) {
LOG(WARNING) << "Invalid ignore_above_value format: " << ignore_above_value
<< ", using default, error: " << e.what();
Copy link
Member

Choose a reason for hiding this comment

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

need to return Status::ErrorErrorCode::INVERTED_INDEX_CLUCENE_ERROR()

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.

9 participants