-
Notifications
You must be signed in to change notification settings - Fork 14
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
client: Accept context parameter in Dial
#346
client: Accept context parameter in Dial
#346
Conversation
cthulhu-rider
commented
Oct 3, 2022
- based on and blocked by rpc/client: Use dial timeout properly neofs-api-go#419
- closes Use context during client dial #343
f33ed86
to
e4fa564
Compare
In previous implementation of `Client.Dial` there was no ability to specify parent context (e.g. global application context). Add `PrmDial.SetContext` method which accepts optional base dial context. Use the context to open client connection or fall back to using `context.Background()`. Upgraded version of `github.com/nspcc-dev/neofs-api-go/v2` module also fixes the problem when dial timeout didn't work properly. Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
After recent changes `client.Client` accepts dial context. There is a need to forward the context passed into `Pool.Dial` to the underlying `Client` instances. Define type aliases of different client constructors: context-based and non-context. Use context-based constructor in `Pool`. Pass `ctx` parameter of `Pool.Dial` method to the client builder. Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
e4fa564
to
c3398dc
Compare
@@ -100,7 +106,13 @@ func (c *Client) Dial(prm PrmDial) error { | |||
c.setNeoFSAPIServer((*coreServer)(&c.c)) | |||
|
|||
// TODO: (neofs-api-go#382) perform generic dial stage of the client.Client | |||
_, _ = rpc.Balance(&c.c, new(v2accounting.BalanceRequest)) | |||
_, err := rpc.Balance(&c.c, new(v2accounting.BalanceRequest), | |||
client.WithContext(prm.parentCtx), |
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 if it is not set?
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.
context.Background()
is used.
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.
Works great to fix nspcc-dev/neofs-s3-gw#712