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(store): respect context in flushLoop #214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cristaloleg
Copy link
Contributor

Overview

After #211 we can improve Store[H].flushLoop a bit more: respect context. Also, added a test to verify that retries works.

Lowered max sleep from 1sec, 100msec should be enough.

@@ -511,3 +514,16 @@ func indexTo[H header.Header[H]](ctx context.Context, batch datastore.Batch, hea
}
return nil
}

// sleep with cancellation, returns nil when timer has fired, error otherwise.
func sleep(ctx context.Context, duration time.Duration) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly this func isn't presented in stdlib sync package :(

CC: https://github.com/cristalhq/synx


assert.Eventually(t, func() bool {
// accessing store.ds directly because inside store we use wrappedStore,
// accessing ds or rootDS directly will result in constant error due to key prefix.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cost me 30min of my life :\

const maxRetrySleep = 100 * time.Millisecond
sleepDur := min(10*time.Duration(i+1)*time.Millisecond, maxRetrySleep)

if err := sleep(ctx, sleepDur); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't that the case that this context is never canceled in practice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Step 1: make to respect context.
Step 2: change context to something real.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants