You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’ve been working through adding support for custom resource timeouts to Terraform - which means we’ve been adding Context to every field.
During this process I’ve noticed that Go-AutoRest doesn’t handle context properly - and only does so within the “Prepare” method (whereas Sender and Responder means this doesn’t work as expected). The current behaviour is to add the PollingDuration field (set at the Client level) to the passed in context and run with that.
Unfortunately we’re unable to use the PollingDuration field as it’s scoped to the client, which means since we reuse the clients (to reuse auth tokens) - setting the PollingDuration at this level means it’s not possible to reuse clients, since there’s the potential for conflicts where different callers have different timeouts (and thus Caller B’s timeout impacts Caller A).
Taking a look at the code, I believe it’s possible to solve this by making the PollingDuration field on the client nilable (read: a pointer) - which means nil-checks could be used to either use the timeout from the context cancelling (if it’s nil) - or to use the current behaviour (if a timeout is specified). This allows users of the SDK to pass in a context that’s pre-configured (with a time-out and the “cancel” method deferred) which means the context is scoped to the given API call (which in most cases should be the WaitForCompletionRef method).
Since I was prototyping this anyway whilst investigating it - I've opened #315 which includes this proposed change, but it’s as yet untested (I’ll handle that shortly) - but I figured I’d check for feedback before proceeding any further - what do you think? :)
Thanks!
The text was updated successfully, but these errors were encountered:
👋
I’ve been working through adding support for custom resource timeouts to Terraform - which means we’ve been adding Context to every field.
During this process I’ve noticed that Go-AutoRest doesn’t handle context properly - and only does so within the “Prepare” method (whereas Sender and Responder means this doesn’t work as expected). The current behaviour is to add the
PollingDuration
field (set at the Client level) to the passed in context and run with that.Unfortunately we’re unable to use the
PollingDuration
field as it’s scoped to the client, which means since we reuse the clients (to reuse auth tokens) - setting thePollingDuration
at this level means it’s not possible to reuse clients, since there’s the potential for conflicts where different callers have different timeouts (and thus Caller B’s timeout impacts Caller A).Taking a look at the code, I believe it’s possible to solve this by making the
PollingDuration
field on the client nilable (read: a pointer) - which means nil-checks could be used to either use the timeout from the context cancelling (if it’s nil) - or to use the current behaviour (if a timeout is specified). This allows users of the SDK to pass in a context that’s pre-configured (with a time-out and the “cancel” method deferred) which means the context is scoped to the given API call (which in most cases should be theWaitForCompletionRef
method).Since I was prototyping this anyway whilst investigating it - I've opened #315 which includes this proposed change, but it’s as yet untested (I’ll handle that shortly) - but I figured I’d check for feedback before proceeding any further - what do you think? :)
Thanks!
The text was updated successfully, but these errors were encountered: