-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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 { |
There was a problem hiding this comment.
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 :(
|
||
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. |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.