requestOne with timeout causes multiple responses
See original GitHub issueLet’s say I have one client who makes a requestOne call that exceeds the specified timeout, the callback will be called when the timeout is exceeded, as well as when the subscriber responds:
Client:
nats.requestOne('help', '', {}, 1000, function(response) {
if(response instanceof NATS.NatsError && response.code === NATS.REQ_TIMEOUT) {
console.log('Request for help timed out.');
return;
}
console.log('Got a response for help: ', response);
});
Subscriber:
nats.subscribe('help', {queue:'help-service'}, function(request, replyTo) {
setTimeout(function() {
nats.publish(replyTo, 'I can help!');
}, 10000);
});
Notice that the Client’s timeout is 1s, but the Subscriber will take 10s to respond.
The client will output “Request for help timed out.”, then output “Got a response for help: I can help!”
The expected output should just be “Request for help timed out.”
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
requestOne with timeout causes multiple responses · Issue #135
Notice that the Client's timeout is 1s, but the Subscriber will take 10s to respond. The client will output "Request for help timed...
Read more >6 Introduction to Interaction Patterns in a BPEL Process
In an asynchronous interaction with a timeout (which you perform in BPEL with a pick activity), a client sends a request to a...
Read more >HTTP Post - Time Out - Multiple Request getting initiated ...
Please let us know What causes this multiple requests to get initiated? Is this due to HTTP POST in general or because of...
Read more >RFC 3261 SIP: Session Initiation Protocol - IETF
SIP runs on top of several different transport protocols. ... When a timeout error is received from the transaction layer, it MUST be...
Read more >The 6 Types of HTTP Status Codes Explained - DYNO Mapper
207 Multi-Status (WebDAV; RFC 4918). A 207 message indicates that the response that follows is an XML message. This message can include a ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just to add a few thoughts on this - while the client may behave as expected as it is today, if the client does not unsubscribe, it leaves a subscription on the server for the lifetime of the connection. With many requests, these subscription leaks will impact the server. While this can be general problem in client design outside of request/reply, it should be addressed here as @aricart noted, for sake of the server under typical request/reply usage.
Not quite sure that I understand what you are saying. So let me try here:
When you unsubscribe, locally the node client will remove its subscription mapping. If a message doesn’t have a matching subscription, it gets dropped. Since the node client is single threaded, when the unsubscribe is processed, the subscription is removed. If a new message is already in the buffer for the client during the unsubscribe, there’s no matching subscription when the message processing happens. Similarly if the server happens to forward a message before processing the unsubscribe, it is will get sent to the client, but the client should drop it.
In this case (the issue raised here), the subscription is still active on the client (and the server) until
unsubscribe
is called.