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
v0.5.0 of gopcua changed the signature of (*Client).Close to accept a context.Context for carrying cancellation signals. However, this means that the "obvious" way of using the client will now be prone to bugs:
If we use the same cancellation signals for the (*Client).Close call and the parent context is cancelled, we will just skip any cleanup and terminate the connection without correctly releasing resources on the server.
This is of course resolvable in user code by separating the contexts used, but I think that it still warrants some discussion about the API. I see three possible ways of implementing the method:
Take context.Context, respect cancellation signal. This is the current behavior, and while it is the most predicable option it is as mentioned prone to misuse. This should probably be pointed out in documentation.
Take context.Context, ignore cancellation signal. This would make the obvious usage more correct, at the cost of making the code less predictable. It does seem weird to completely ignore the input given by the user, and would probably lead to more subtle bugs down the line.
Don't take context.Context, use internal cancellation signals. Would be difficult to misuse, but would also take away control from the user.
I think that I'm still in favor of the current behavior, just that it needs to be called out more explicitly in documentation IMO.
The text was updated successfully, but these errors were encountered:
v0.5.0
of gopcua changed the signature of(*Client).Close
to accept acontext.Context
for carrying cancellation signals. However, this means that the "obvious" way of using the client will now be prone to bugs:If we use the same cancellation signals for the
(*Client).Close
call and the parent context is cancelled, we will just skip any cleanup and terminate the connection without correctly releasing resources on the server.This is of course resolvable in user code by separating the contexts used, but I think that it still warrants some discussion about the API. I see three possible ways of implementing the method:
context.Context
, respect cancellation signal. This is the current behavior, and while it is the most predicable option it is as mentioned prone to misuse. This should probably be pointed out in documentation.context.Context
, ignore cancellation signal. This would make the obvious usage more correct, at the cost of making the code less predictable. It does seem weird to completely ignore the input given by the user, and would probably lead to more subtle bugs down the line.context.Context
, use internal cancellation signals. Would be difficult to misuse, but would also take away control from the user.I think that I'm still in favor of the current behavior, just that it needs to be called out more explicitly in documentation IMO.
The text was updated successfully, but these errors were encountered: