servicetalk
servicetalk copied to clipboard
Handle cancelation after ConnectionFactory creates a new connection
ConnectioFactoryFilter
(s) may already create a new connection but work with it before emitting downstream. See ProxyConnectConnectionFactoryFilter as an example. When cancel is received after a new connection is created we need to clean up this resource.
However, cancel()
can come after a success, we really do not know if the cancel has come due to the operation was canceled by the user or due to some operators sending a cancel for the previous source when they move on to the next source (eg: concat()
). Connection lifetime is anyways a problem in such situation and is out of the context of each filter implementation.
See https://github.com/apple/servicetalk/pull/1002#discussion_r404538544 for more context.
Cancellation is a path in which a connection MAY get "lost" in the execution chain. Early termination is another.
Lack of control on lifetime of objects in asynchronous execution chain of operators is one of the reason why we do not use reference counted objects. Connection is just another example where a lifetime is associated with an object and hence there is no guarantee that eventually the connection will be closed once it is emitted in an asynchronous execution chain.