{"action":"created","issue":{"url":"https://api.github.com/repos/nats-io/csnats/issues/73","repository_url":"https://api.github.com/repos/nats-io/csnats","labels_url":"https://api.github.com/repos/nats-io/csnats/issues/73/labels{/name}","comments_url":"https://api.github.com/repos/nats-io/csnats/issues/73/comments","events_url":"https://api.github.com/repos/nats-io/csnats/issues/73/events","html_url":"https://github.com/nats-io/csnats/issues/73","id":156934671,"number":73,"title":"Request Problem","user":{"login":"s921102002","id":19200719,"avatar_url":"https://avatars.githubusercontent.com/u/19200719?v=3","gravatar_id":"","url":"https://api.github.com/users/s921102002","html_url":"https://github.com/s921102002","followers_url":"https://api.github.com/users/s921102002/followers","following_url":"https://api.github.com/users/s921102002/following{/other_user}","gists_url":"https://api.github.com/users/s921102002/gists{/gist_id}","starred_url":"https://api.github.com/users/s921102002/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s921102002/subscriptions","organizations_url":"https://api.github.com/users/s921102002/orgs","repos_url":"https://api.github.com/users/s921102002/repos","events_url":"https://api.github.com/users/s921102002/events{/privacy}","received_events_url":"https://api.github.com/users/s921102002/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-26T08:51:43Z","updated_at":"2016-05-26T15:55:49Z","closed_at":null,"body":"Hi, I play the example Requestor and Replier.\r\nI found there's a exception when  request return because\r\nIn Conn.cs\r\n```\r\n        internal virtual Msg request(string subject, byte[] data, int timeout)\r\n        {\r\n            Msg    m     = null;\r\n            string inbox = NewInbox();\r\n\r\n            SyncSubscription s = subscribeSync(inbox, null);\r\n            s.AutoUnsubscribe(1);\r\n\r\n            publish(subject, inbox, data);\r\n            m = s.NextMessage(timeout);\r\n            try\r\n            {\r\n                // the auto unsubscribe should handle this.\r\n                s.Unsubscribe();\r\n            }\r\n            catch (Exception) {  /* NOOP */ }\r\n\r\n            return m;\r\n        }\r\n```\r\n\r\nwhen s.NextMessage(timeout);\r\n```\r\n            if (msg != null)\r\n            {\r\n                long d = tallyDeliveredMessage(msg);\r\n                if (d == max)\r\n                {\r\n                    // Remove subscription if we have reached max.\r\n                    localConn.removeSub(this);\r\n                }\r\n                if (localMax > 0 && d > localMax)\r\n                {\r\n                    throw new NATSMaxMessagesException();\r\n                }\r\n            }\r\n```\r\n\r\n  localConn.removeSub(this);\r\n\r\nso \r\n\r\n```\r\n       internal virtual void removeSub(Subscription s)\r\n        {\r\n            Subscription o;\r\n\r\n            subs.TryRemove(s.sid, out o);\r\n            if (s.mch != null)\r\n            {\r\n                s.mch.close();\r\n                s.mch = null;\r\n            }\r\n\r\n            s.conn = null;\r\n            s.closed = true;\r\n        }\r\n```\r\n\r\ns.conn = null; here, but next return to Conn.cs and execute\r\n\r\n```\r\n              // the auto unsubscribe should handle this.\r\n                s.Unsubscribe();\r\n```\r\n\r\n```\r\n        public virtual void Unsubscribe()\r\n        {\r\n            Connection c;\r\n            lock (mu)\r\n            {\r\n                c = this.conn;\r\n            }\r\n\r\n            if (c == null)\r\n                throw new NATSBadSubscriptionException();\r\n\r\n            c.unsubscribe(this, 0);\r\n        }\r\n```\r\n\r\nthe exception here\r\n```\r\n if (c == null)\r\n    throw new NATSBadSubscriptionException();\r\n```\r\nI have two problems\r\n\r\n1. when execute request and the max count =1 and unsubscribe in NextMessage() function so c always null here and the exception always throw?\r\n\r\n2.if throw new NATSBadSubscriptionException();  it has significant impact on performance, and Is this a bug? or can I delete this exception such as if (c == null) return; ???\r\n\r\nor is there something wrong with me?\r\n\r\nThanks All"},"comment":{"url":"https://api.github.com/repos/nats-io/csnats/issues/comments/221913719","html_url":"https://github.com/nats-io/csnats/issues/73#issuecomment-221913719","issue_url":"https://api.github.com/repos/nats-io/csnats/issues/73","id":221913719,"user":{"login":"ColinSullivan1","id":11180189,"avatar_url":"https://avatars.githubusercontent.com/u/11180189?v=3","gravatar_id":"","url":"https://api.github.com/users/ColinSullivan1","html_url":"https://github.com/ColinSullivan1","followers_url":"https://api.github.com/users/ColinSullivan1/followers","following_url":"https://api.github.com/users/ColinSullivan1/following{/other_user}","gists_url":"https://api.github.com/users/ColinSullivan1/gists{/gist_id}","starred_url":"https://api.github.com/users/ColinSullivan1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ColinSullivan1/subscriptions","organizations_url":"https://api.github.com/users/ColinSullivan1/orgs","repos_url":"https://api.github.com/users/ColinSullivan1/repos","events_url":"https://api.github.com/users/ColinSullivan1/events{/privacy}","received_events_url":"https://api.github.com/users/ColinSullivan1/received_events","type":"User","site_admin":false},"created_at":"2016-05-26T15:55:48Z","updated_at":"2016-05-26T15:55:48Z","body":"Hello @s921102002, thank you for your interest in NATS!  Good observations!\r\n\r\n1) That is present to parallel the go client - the Unsubscription is there to cover the case the server did not process the message or a failover happened down during the request.  In most cases it should have no effect.\r\n2) There is a performance impact.  I'm not sure how significant it is with respect to the entire request reply call, but good catch there!\r\n\r\nI've updated to account for these with #75.  Does this address your questions/issues?"}}
{"actor":{"display_login":"ColinSullivan1"}}