nats-io / stan.go

NATS Streaming System
https://nats.io
Apache License 2.0
706 stars 117 forks source link

[FIXED] Subscribe timeout should send a close request #347

Closed kozlovic closed 3 years ago

kozlovic commented 3 years ago

If an application gets a timeout on a Subscribe() call, it does not know if the server is actually going to process the request. The request could have been just processed but the client timed-out before getting the response back, or there is a bit of a backlog of requests in the server and the request will be processed after the request times out in the client.

If that happens, and if the application maintains its connection, then it is possible that the server processes the subscription and keep that subscription alive, although the application does not have an handle on this subscription (the Subscribe() call has failed).

On timeout, the library will now send a request to close the subscription. However, the protocol normally requires the AckInbox which is assigned by the server and sent back as part of the subscription response protocol. The library will send the request with the subscription inbox. Newer servers (v0.21.0+) will be able to handle that, older will report that no subscription was found for the subscription close request.

Signed-off-by: Ivan Kozlovic ivan@synadia.com

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.1%) to 92.996% when pulling 6e449118ab47639ac7ebee4291ae20a61e9e9890 on fix_sub_req_timeout_handling into cebf22c80c6223c08a3345eea76f5cd3beb86984 on master.