-
Notifications
You must be signed in to change notification settings - Fork 16
Fix indefinitely stuck consumer on fetch DeadlineExceeded #720
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
105ae85
Log fetch error with exponential backoff
carsonip 70cbe8b
Check client context
carsonip f61db6d
Fix log
carsonip ea96868
Propagate a specific error
carsonip 7205d92
Actually sleep
carsonip 9e5e8b9
Unexport
carsonip 4f3c416
Fix var
carsonip 7d68dde
Better log
carsonip c5dd68c
Respect client ctx during backoff
carsonip 3f92fbe
Use fetchErr
carsonip 3828da8
Remove backoff
carsonip fc5cef1
Only retry deadline exceeded
carsonip 1310ad0
Retry context canceled as well
carsonip c29f219
Clearer control flow
carsonip bf3217c
Log non-canceled error on canceled
carsonip b5afff6
Wrap error
carsonip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -352,12 +352,22 @@ func (c *Consumer) Run(ctx context.Context) error { | |
| var clientCtx context.Context | ||
| clientCtx, c.stopPoll = context.WithCancel(ctx) | ||
| c.mu.Unlock() | ||
|
|
||
| for { | ||
| if err := c.fetch(clientCtx); err != nil { | ||
| if errors.Is(err, context.Canceled) { | ||
| return nil // Return no error if err == context.Canceled. | ||
| if errors.Is(clientCtx.Err(), context.Canceled) { | ||
| if !errors.Is(err, context.Canceled) { | ||
| c.cfg.Logger.Error("consumer: fetch error on context canceled", zap.Error(err)) | ||
| } | ||
| return nil // Return no error if client context is canceled. | ||
| } | ||
| return fmt.Errorf("cannot fetch records: %w", err) | ||
|
|
||
| if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { | ||
| c.cfg.Logger.Error("consumer: fetch error; retrying", zap.Error(err)) | ||
| continue | ||
| } | ||
|
|
||
| return fmt.Errorf("consumer fetch error: %w", err) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -368,10 +378,10 @@ func (c *Consumer) fetch(ctx context.Context) error { | |
| fetches := c.client.PollRecords(ctx, c.cfg.MaxPollRecords) | ||
| defer c.client.AllowRebalance() | ||
|
|
||
| if fetches.IsClientClosed() || | ||
| errors.Is(fetches.Err0(), context.Canceled) || | ||
| errors.Is(fetches.Err0(), context.DeadlineExceeded) { | ||
| return context.Canceled | ||
| if fetchErr := fetches.Err0(); errors.Is(fetchErr, kgo.ErrClientClosed) || | ||
| errors.Is(fetchErr, context.Canceled) || | ||
| errors.Is(fetchErr, context.DeadlineExceeded) { | ||
| return fetchErr | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this fix, we were masking the underlying error here.... |
||
| } | ||
| c.mu.RLock() | ||
| defer c.mu.RUnlock() | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we please add some follow-up comments on this code block? I find it pretty confusing to read.
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.
#721