{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/amqpnetlite/issues/91","repository_url":"https://api.github.com/repos/Azure/amqpnetlite","labels_url":"https://api.github.com/repos/Azure/amqpnetlite/issues/91/labels{/name}","comments_url":"https://api.github.com/repos/Azure/amqpnetlite/issues/91/comments","events_url":"https://api.github.com/repos/Azure/amqpnetlite/issues/91/events","html_url":"https://github.com/Azure/amqpnetlite/issues/91","id":132355731,"number":91,"title":"Potential Deadlock","user":{"login":"anirudhsanthiar","id":12654369,"avatar_url":"https://avatars.githubusercontent.com/u/12654369?v=3","gravatar_id":"","url":"https://api.github.com/users/anirudhsanthiar","html_url":"https://github.com/anirudhsanthiar","followers_url":"https://api.github.com/users/anirudhsanthiar/followers","following_url":"https://api.github.com/users/anirudhsanthiar/following{/other_user}","gists_url":"https://api.github.com/users/anirudhsanthiar/gists{/gist_id}","starred_url":"https://api.github.com/users/anirudhsanthiar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anirudhsanthiar/subscriptions","organizations_url":"https://api.github.com/users/anirudhsanthiar/orgs","repos_url":"https://api.github.com/users/anirudhsanthiar/repos","events_url":"https://api.github.com/users/anirudhsanthiar/events{/privacy}","received_events_url":"https://api.github.com/users/anirudhsanthiar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-09T08:05:21Z","updated_at":"2016-02-10T03:10:30Z","closed_at":null,"body":"The ```Connect``` method in TcpTransport.cs could deadlock. The method is:\r\n```\r\n public void Connect(Connection connection, Address address, bool noVerification)\r\n {\r\n    this.connection = connection;\r\n    var factory = new ConnectionFactory();\r\n    if (noVerification)\r\n    {\r\n    \tfactory.SSL.RemoteCertificateValidationCallback = noneCertValidator;\r\n    }\r\n\r\n    this.ConnectAsync(address, factory).GetAwaiter().GetResult();\r\n}\r\n```\r\nA GUI client (such as a Windows Forms app) or an MVC client will deadlock if it calls the method as follows:\r\n\r\n```\r\nconst string Endpoint = \"amqp://guest:guest@localhost:5765\";           \r\nAddress address = new Address(Endpoint);\r\nvar connection = new Connection(address);\r\n```\r\n(The constructor for the ```Connection object``` eventually calls the Connect method above.)\r\n\r\nNote that the connect method blocks on a Task object because of the call to ```GetResult```: \r\n```this.ConnectAsync(address, factory).GetAwaiter().GetResult();```\r\nBlocking on Task objects (Via Task.Wait() or Task.Result or Task.GetAwaiter().GetResult()) \r\nis dangerous and could result in deadlocks.\r\n(See, for example http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html)"},"comment":{"url":"https://api.github.com/repos/Azure/amqpnetlite/issues/comments/182178713","html_url":"https://github.com/Azure/amqpnetlite/issues/91#issuecomment-182178713","issue_url":"https://api.github.com/repos/Azure/amqpnetlite/issues/91","id":182178713,"user":{"login":"anirudhsanthiar","id":12654369,"avatar_url":"https://avatars.githubusercontent.com/u/12654369?v=3","gravatar_id":"","url":"https://api.github.com/users/anirudhsanthiar","html_url":"https://github.com/anirudhsanthiar","followers_url":"https://api.github.com/users/anirudhsanthiar/followers","following_url":"https://api.github.com/users/anirudhsanthiar/following{/other_user}","gists_url":"https://api.github.com/users/anirudhsanthiar/gists{/gist_id}","starred_url":"https://api.github.com/users/anirudhsanthiar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anirudhsanthiar/subscriptions","organizations_url":"https://api.github.com/users/anirudhsanthiar/orgs","repos_url":"https://api.github.com/users/anirudhsanthiar/repos","events_url":"https://api.github.com/users/anirudhsanthiar/events{/privacy}","received_events_url":"https://api.github.com/users/anirudhsanthiar/received_events","type":"User","site_admin":false},"created_at":"2016-02-10T03:10:30Z","updated_at":"2016-02-10T03:10:30Z","body":"Yes, that would be great. Another option is to configure the await statements in ampqnetlite to not capture context via ConfigureAwait(false) [see, for example, the section under \"avoiding context\" in [1](http://blog.stephencleary.com/2012/02/async-and-await.html)]"}}