-
Notifications
You must be signed in to change notification settings - Fork 741
sync
-- client cleanup
#1680
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
sync
-- client cleanup
#1680
Conversation
lastErr = err | ||
time.Sleep(failedRequestSleepInterval) |
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.
Removed to avoid sleeping. It's not the end of the world to wait 10 ms to wake up in the event of context cancellation, but still seems like good practice to not sleep.
// or [ctx] is canceled. | ||
// Returns the peer's NodeID and response. | ||
// It's safe to call this method multiple times concurrently. | ||
func (c *client) get(ctx context.Context, request []byte) (ids.NodeID, []byte, 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.
In other places like this we return the node ID first so I did that here too
func (c *networkClient) AppRequestFailed(_ context.Context, nodeID ids.NodeID, requestID uint32) error { | ||
// Always returns nil because the engine considers errors | ||
// returned from this function as fatal. | ||
func (c *networkClient) AppRequestFailed( |
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.
I don't think it's necessary to rewrite the semantics of AppRequestFailed here
if err := c.activeRequests.Acquire(ctx, 1); err != nil { | ||
return nil, ErrAcquiringSemaphore | ||
} | ||
defer c.activeRequests.Release(1) |
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.
Moved releases for this semaphore to be in the two places we acquire from it
handler := newResponseHandler() | ||
c.outstandingRequestHandlers[requestID] = handler |
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 wait to register this until we've successfully sent the request
x/sync/client.go
Outdated
// Return error at top of loop. | ||
// Don't do it here to avoid duplicate code. | ||
case <-time.After(failedRequestSleepInterval): | ||
// TODO should we randomize this? |
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.
What benefit would randomization have?
We could consider adding exponential backoff.
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.
Just trying to prevent retry storms. I'll add exponential backoff in a follow up PR.
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.
Why this should be merged
Cleanup
How this works
Comments, nits and other small changes to improve readability and make the code easier to understand.
How this was tested
Existing UT.