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

polygon/sync: blockdownloader to use common.Sleep #10467

Merged
merged 5 commits into from
May 28, 2024

Conversation

taratorio
Copy link
Member

@taratorio taratorio commented May 24, 2024

Original intent of this PR was to replace 1 usage of time.Sleep in polygon/sync/block_downloader.go with common.Sleep which is context-aware.

However when doing this we discussed that common.Sleep can be improved to return an err to the caller when the parent ctx has been cancelled so that the caller is made aware of that without having to make subsequent checks.

@@ -149,7 +149,7 @@ func (d *blockDownloader) downloadBlocksUsingWaypoints(ctx context.Context, wayp
"sleepSeconds", d.notEnoughPeersBackOffDuration.Seconds(),
)

time.Sleep(d.notEnoughPeersBackOffDuration)
common.Sleep(ctx, d.notEnoughPeersBackOffDuration)
Copy link
Collaborator

Choose a reason for hiding this comment

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

are you sure that don't need to check err?

Copy link
Member Author

Choose a reason for hiding this comment

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

common.Sleep does not return an err

Copy link
Member Author

Choose a reason for hiding this comment

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

seems like you and @mh0lt may be suggesting that it should be returning an error if the parent ctx timeout/got cancelled so the caller knows - is this right?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok talked on chat with Mark so will make changes to:

  • return err from common.Sleep coming from parentCtx.Err (once it is done)
  • use time.NewTimer for the sleep time since it plays better with parentCtx.Done (timer gives us a channel to block on like ctx.Done)

Copy link
Contributor

@mh0lt mh0lt left a comment

Choose a reason for hiding this comment

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

I have the same question as alex.

I assume the benefit of this over time.Sleep is that if the context gets cancelled then the sleep will return, however the way this is used here this is ignored. I think it should possibly check the err and return if cancelled rather than timed out ?

Although looking at the code - it seems like it forces a cancel - rather than using the parent - so perhaps this is a moot point ?

@taratorio
Copy link
Member Author

taratorio commented May 27, 2024

@mh0lt @AskAlexSharov common.Sleep does not return an err. I'm not sure I follow what you mean.

---> talked offline, the suggestion from Mark is to return an err to the caller to indicate to that the ctx has been cancelled/timed out

@taratorio taratorio merged commit afcfe62 into main May 28, 2024
10 checks passed
@taratorio taratorio deleted the astrid-bd-common-sleep branch May 28, 2024 10:10
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.

4 participants