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

Adding model::no_timeout to a duration overflows #3184

Closed
graphcareful opened this issue Dec 7, 2021 · 1 comment
Closed

Adding model::no_timeout to a duration overflows #3184

graphcareful opened this issue Dec 7, 2021 · 1 comment
Labels
good first issue Good for newcomers kind/bug Something isn't working

Comments

@graphcareful
Copy link
Contributor

graphcareful commented Dec 7, 2021

There are some places in the codebase where a model::timeout_clock::duration is accepted as parameter. In these sites this value is commonly added to model::timeout_clock::now().

The issue arises when model::no_timeout is passed as duration parameter like so:

        return create_topics(
          without_custom_assignments(std::move(topics)),
          model::timeout_clock::now() + timeout);

This overflows, which is bad because depending on the nature of the result of the addition, it may be the case that the actual timeout is a very small value. Proof of the overflow is provided in this tiny unit test:

#include <seastar/core/lowres_clock.hh>
#include <seastar/testing/thread_test_case.hh>

SEASTAR_THREAD_TEST_CASE(timer_test) {
    const auto max = seastar::lowres_clock_impl::steady_duration::max();
    const auto max_tp = seastar::lowres_clock_impl::steady_time_point::max();
    const auto now = seastar::lowres_clock_impl::steady_now();
    BOOST_CHECK((now + max) == max_tp);
}

Here is the result:

Running 1 test case...
WARNING: debug mode. Not for benchmarking or production
random-seed=2453175103
==1400454==WARNING: ASan doesn't fully support makecontext/swapcontext functions and may produce false positives in some cases!
/home/robert/workspace/redpanda/vbuild/llvm/install/bin/../include/c++/v1/chrono:1249:35: runtime error: signed integer overflow: 62891062 + 9223372036854775807 cannot be represented in type 'long long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/robert/workspace/redpanda/vbuild/llvm/install/bin/../include/c++/v1/chrono:1249:35 in 
../../../src/v/coproc/tests/tt.cc(18): error: in "timer_test": check (now + max) == max_tp has failed

Why haven't we seen an issue with create_topics? Probably because clients always pass a sane timeout when creating a topic. However this issue was just observed with #3119 during testing and it was found that it can be an issue elsewhere in the codebase too.

JIRA Link: CORE-793

@graphcareful graphcareful added the kind/bug Something isn't working label Dec 7, 2021
@graphcareful graphcareful mentioned this issue Dec 7, 2021
@dotnwat dotnwat added the good first issue Good for newcomers label Dec 8, 2021
@bharathv bharathv self-assigned this Jun 3, 2022
@bharathv
Copy link
Contributor

bharathv commented Jun 3, 2022

Assigning to myself, seems like good first issue (and still seems relevant).

@bharathv bharathv removed their assignment Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants