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

[v24.2.x] [CORE-7058]: storage: fix race condition in segment::release_appender_in_background() #24559

Merged

Conversation

vbotbuildovich
Copy link
Collaborator

Backport of PR #24483

…ound()`

This function caused race conditions between `segment::close()` and
a segment roll.

Consider the following sequence of events:

1. `_gate.close()` called in `segment::close()`
2. `auto a = std::exchange(_appender, nullptr)` called
    in `segment::release_appender_in_background()`
3. `ssx::spawn_with_gate()` called in `segment::release_appender_in_background()`
4. `return ignore_shutdown_exceptions()` in `ssx::spawn_with_gate()`
5. rest of `release_appender_in_background()` is ignored
6. `a` goes out of scope in `release_appender_in_background()` without
   `close()`ing the `appender`
7. one sad panda

Add an explicit check to `_gate.check()` in `release_appender_in_background()`
to throw an exception in case the gate is closed, and defer the closing of the
appender to `segment::close()` in order to avoid the potential race condition here.

(cherry picked from commit edc0ab3)
If the dirty offset is default initialized to `int64_t::min()`
and not updated before a segment is force rolled, an assert will fail
in `disk_log_impl::new_segment()` for the offset being < 0.

Use `model::next_offset()` instead of simply adding `1` to the dirty offset
to avoid this case.

(cherry picked from commit 7a29f24)
To test race conditions between `segment::close()` and a segment roll,
particularly one which goes through `release_appender_in_background()`.

(cherry picked from commit 24ec834)
@vbotbuildovich vbotbuildovich added this to the v24.2.x-next milestone Dec 13, 2024
@vbotbuildovich vbotbuildovich added the kind/backport PRs targeting a stable branch label Dec 13, 2024
@WillemKauf WillemKauf merged commit 2f1cb87 into redpanda-data:v24.2.x Dec 13, 2024
18 checks passed
@aanthony-rp aanthony-rp modified the milestones: v24.2.x-next, 24.2.14 Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redpanda kind/backport PRs targeting a stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants