Skip to content

fix: cache: stop the watcher on drop, also while establishing - #11

Merged
drmingdrmer merged 1 commit into
databendlabs:mainfrom
drmingdrmer:eventwatcher-dropping-the-cache-does
Nov 18, 2026
Merged

drmingdrmer merged 1 commit into
databendlabs:mainfrom
drmingdrmer:eventwatcher-dropping-the-cache-does

Conversation

@drmingdrmer

Copy link
Copy Markdown
Member

Changelog

fix: cache: stop the watcher on drop, also while establishing

Summary

A watcher stops when its Cache is dropped, whatever it waits for:
the retries of subscribe while the source is unreachable, the
5-minute delay after subscribe returned Unsupported, or an initial
flush that does not finish.

Details

EventWatcher::main observed its cancel future only inside
watch_kv_changes. It now races the retry delay, retry_new_stream()
and initialize_cache() against it too, with futures::select!, and
returns when it is ready. Before, a caller that rebuilt a Cache,
e.g. to resync, leaked one watcher task, holding its Source, per
rebuild while the source was unreachable or unsupported.

The data lock is not raced: readers hold it only through a &Cache,
so it is free once the Cache is dropped.

Fixes: #10


  • Bug Fix

# Summary

A watcher stops when its `Cache` is dropped, whatever it waits for:
the retries of `subscribe` while the source is unreachable, the
5-minute delay after `subscribe` returned `Unsupported`, or an initial
flush that does not finish.

# Details

`EventWatcher::main` observed its cancel future only inside
`watch_kv_changes`. It now races the retry delay, `retry_new_stream()`
and `initialize_cache()` against it too, with `futures::select!`, and
returns when it is ready. Before, a caller that rebuilt a `Cache`,
e.g. to resync, leaked one watcher task, holding its `Source`, per
rebuild while the source was unreachable or unsupported.

The data lock is not raced: readers hold it only through a `&Cache`,
so it is free once the `Cache` is dropped.

Fixes: databendlabs#10

@xp-trumpet xp-trumpet left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@xp-trumpet reviewed 3 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on drmingdrmer).

@drmingdrmer
drmingdrmer merged commit ed1446c into databendlabs:main Nov 18, 2026
6 checks passed
@drmingdrmer
drmingdrmer deleted the eventwatcher-dropping-the-cache-does branch November 18, 2026 11:58
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.

EventWatcher: dropping the Cache does not stop a watcher that is establishing the cache

2 participants