{"action":"created","issue":{"url":"https://api.github.com/repos/Code-Sharp/WampSharp/issues/151","repository_url":"https://api.github.com/repos/Code-Sharp/WampSharp","labels_url":"https://api.github.com/repos/Code-Sharp/WampSharp/issues/151/labels{/name}","comments_url":"https://api.github.com/repos/Code-Sharp/WampSharp/issues/151/comments","events_url":"https://api.github.com/repos/Code-Sharp/WampSharp/issues/151/events","html_url":"https://github.com/Code-Sharp/WampSharp/issues/151","id":183878779,"number":151,"title":"Memory and handle leak, when WampHost.Start() has been called and disposed.","user":{"login":"bigbearzhu","id":1924924,"avatar_url":"https://avatars.githubusercontent.com/u/1924924?v=3","gravatar_id":"","url":"https://api.github.com/users/bigbearzhu","html_url":"https://github.com/bigbearzhu","followers_url":"https://api.github.com/users/bigbearzhu/followers","following_url":"https://api.github.com/users/bigbearzhu/following{/other_user}","gists_url":"https://api.github.com/users/bigbearzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/bigbearzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigbearzhu/subscriptions","organizations_url":"https://api.github.com/users/bigbearzhu/orgs","repos_url":"https://api.github.com/users/bigbearzhu/repos","events_url":"https://api.github.com/users/bigbearzhu/events{/privacy}","received_events_url":"https://api.github.com/users/bigbearzhu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-10-19T06:45:30Z","updated_at":"2016-10-21T06:21:31Z","closed_at":null,"body":"We experienced some memory leak when we have retry on starting a WampHost when there is socket port conflict. The logic is pretty basic: catch exception and retry after a while. Interestingly the memory leak is mostly in unmanaged code, and there are lots of handle leaks too. The handles are leaked mostly in the `WampBindingHost<TMessage>.GetEventSerializer` function, stack trace as below:\r\n```\r\nCastle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget<TInterface>(IInterceptor interceptor)\r\nWampSharp.Core.Serialization.WampMessageSerializerFactory<TMessage>.GetSerializer<TProxy>()\r\nWampSharp.V2.WampBindingHost<TMessage>.GetEventSerializer(IWampOutgoingRequestSerializer outgoingSerializer)\r\n```\r\n\r\nSample code for reproducing the leak:\r\n```\r\nusing System;\r\nusing System.Threading;\r\nusing WampSharp.V2;\r\nusing WampSharp.V2.Authentication;\r\nusing WampSharp.V2.Core.Contracts;\r\n\r\nnamespace ConsoleApplication1\r\n{\r\n    class Program\r\n    {\r\n        static void Main()\r\n        {\r\n            while (true)\r\n            {\r\n                try\r\n                {\r\n                    DefaultWampAuthenticationHost host = new DefaultWampAuthenticationHost($\"ws://0.0.0.0:{4567}/ws\", new WampSessionAuthenticatorFactory());\r\n                    host.Open();\r\n                    host.Dispose();\r\n                }\r\n                catch \r\n                {\r\n                    Thread.Sleep(100);\r\n                    GC.Collect();\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    internal class WampSessionAuthenticatorFactory : IWampSessionAuthenticatorFactory\r\n    {\r\n        public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator)\r\n        {\r\n            return new MockWampSessionAuthenticator();\r\n        }\r\n    }\r\n\r\n    internal class MockWampSessionAuthenticator : WampSessionAuthenticator\r\n    {\r\n        public override void Authenticate(string signature, AuthenticateExtraData extra)\r\n        {\r\n        }\r\n\r\n        public override string AuthenticationId => \"foo\";\r\n        public override string AuthenticationMethod => \"bar\";\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/Code-Sharp/WampSharp/issues/comments/255303365","html_url":"https://github.com/Code-Sharp/WampSharp/issues/151#issuecomment-255303365","issue_url":"https://api.github.com/repos/Code-Sharp/WampSharp/issues/151","id":255303365,"user":{"login":"bigbearzhu","id":1924924,"avatar_url":"https://avatars.githubusercontent.com/u/1924924?v=3","gravatar_id":"","url":"https://api.github.com/users/bigbearzhu","html_url":"https://github.com/bigbearzhu","followers_url":"https://api.github.com/users/bigbearzhu/followers","following_url":"https://api.github.com/users/bigbearzhu/following{/other_user}","gists_url":"https://api.github.com/users/bigbearzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/bigbearzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigbearzhu/subscriptions","organizations_url":"https://api.github.com/users/bigbearzhu/orgs","repos_url":"https://api.github.com/users/bigbearzhu/repos","events_url":"https://api.github.com/users/bigbearzhu/events{/privacy}","received_events_url":"https://api.github.com/users/bigbearzhu/received_events","type":"User","site_admin":false},"created_at":"2016-10-21T06:21:31Z","updated_at":"2016-10-21T06:21:31Z","body":"This is the comparison after over 1 hr wait. I have tried enter many times. And you can probably see how my w3wp.exe leaks too during that time.\r\n![image](https://cloud.githubusercontent.com/assets/1924924/19588595/2673ae1a-97aa-11e6-8a40-d0bd13c16394.png)\r\n"}}
{"actor":{"display_login":"bigbearzhu"}}