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

app/retry: implement async retryer #346

Merged
merged 4 commits into from
Apr 5, 2022
Merged

app/retry: implement async retryer #346

merged 4 commits into from
Apr 5, 2022

Conversation

corverroos
Copy link
Contributor

@corverroos corverroos commented Apr 3, 2022

Package retry provides a generic async slot function executor with retries for robustness against network failures.
Functions are linked to a slot, executed asynchronously and network or context errors retried with backoff
until duties related to a slot have elapsed (5 slots later).

category: feature
ticket: #354

@codecov
Copy link

codecov bot commented Apr 3, 2022

Codecov Report

Merging #346 (5c49189) into main (90abf45) will increase coverage by 0.32%.
The diff coverage is 66.89%.

@@            Coverage Diff             @@
##             main     #346      +/-   ##
==========================================
+ Coverage   55.36%   55.68%   +0.32%     
==========================================
  Files          60       62       +2     
  Lines        5175     5332     +157     
==========================================
+ Hits         2865     2969     +104     
- Misses       1917     1962      +45     
- Partials      393      401       +8     
Impacted Files Coverage Δ
core/retry.go 0.00% <0.00%> (ø)
app/app.go 63.54% <76.92%> (+0.33%) ⬆️
app/retry/retry.go 79.09% <79.09%> (ø)
app/log/log.go 84.81% <100.00%> (+0.39%) ⬆️
p2p/k1.go 0.00% <0.00%> (ø)
cmd/bootnode.go 46.83% <0.00%> (+1.38%) ⬆️
cmd/run.go 100.00% <0.00%> (+4.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 90abf45...5c49189. Read the comment docs.

Comment on lines +1 to +4
00:00 DEBG msg1 {"ctx1": 1, "caller": "log_test.go:44"}
00:00 INFO msg2 {"ctx2": 2, "wrap2": 2, "caller": "log_test.go:45"}
00:00 WARN msg3a {"wrap3": "a", "wrap2": 2, "caller": "log_test.go:46"}
00:00 WARN msg3b {"wrap3": "b", "wrap2": 2, "caller": "log_test.go:47"}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO(corver): Create ticket to stub caller lines from golden files to make it less brittle

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont understand that sentence, what are golden files? and stub caller lines?

Copy link
Contributor Author

@corverroos corverroos Apr 4, 2022

Choose a reason for hiding this comment

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

See here for golden files: https://github.com/sebdah/goldie

This is a caller line: "caller": "log_test.go:47". The line number changes when the test file code changes. That makes the test brittle. Since the logic didn't change.

app/retry/retry.go Outdated Show resolved Hide resolved
app/retry/retry.go Outdated Show resolved Hide resolved
// It is intended to be used asynchronously:
// go retryer.DoAsync(ctx, duty.Slot, "foo", fn)
func (r *Retryer) DoAsync(parent context.Context, slot int64, name string, fn func(context.Context) error) {
defer r.wrapActive()()
Copy link
Contributor

Choose a reason for hiding this comment

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

@corverroos I don't understand what this is doing, because it looks like it will do both calls on defer. Also, it seems that this can be done by the library sync.WaitingGroup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is a pattern to wrap a function in some logic. It is called at the start and end of a function. It increments and decrements the active counter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, changed it to sync.Waitgroup.

Copy link
Contributor

@leolara leolara Apr 5, 2022

Choose a reason for hiding this comment

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

Are you sure, I think it is being called both things at the end of the funciton, like defer wraps both calls. Isn't? @corverroos

Copy link
Contributor

Choose a reason for hiding this comment

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

@corverroos I think you didn't push the change to WaitingGroup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah sorry, pushed now

app/retry/retry.go Show resolved Hide resolved
app/log/testdata/TestErrorWrap Show resolved Hide resolved
app/retry/retry.go Outdated Show resolved Hide resolved
Comment on lines +1 to +4
00:00 DEBG msg1 {"ctx1": 1, "caller": "log_test.go:44"}
00:00 INFO msg2 {"ctx2": 2, "wrap2": 2, "caller": "log_test.go:45"}
00:00 WARN msg3a {"wrap3": "a", "wrap2": 2, "caller": "log_test.go:46"}
00:00 WARN msg3b {"wrap3": "b", "wrap2": 2, "caller": "log_test.go:47"}
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont understand that sentence, what are golden files? and stub caller lines?

Copy link
Contributor

@leolara leolara left a comment

Choose a reason for hiding this comment

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

I like how you have implemented the wg.Wait so that the context can still cancel

@corverroos corverroos merged commit 07a2e54 into main Apr 5, 2022
@corverroos corverroos deleted the corver/retry branch April 5, 2022 10:46
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.

3 participants