{"action":"created","issue":{"url":"https://api.github.com/repos/Particular/NServiceBus/issues/4144","repository_url":"https://api.github.com/repos/Particular/NServiceBus","labels_url":"https://api.github.com/repos/Particular/NServiceBus/issues/4144/labels{/name}","comments_url":"https://api.github.com/repos/Particular/NServiceBus/issues/4144/comments","events_url":"https://api.github.com/repos/Particular/NServiceBus/issues/4144/events","html_url":"https://github.com/Particular/NServiceBus/issues/4144","id":177723863,"number":4144,"title":"Unhandled exceptions and deadlocks when disposing the bus with an external container","user":{"login":"cremor","id":116314,"avatar_url":"https://avatars.githubusercontent.com/u/116314?v=3","gravatar_id":"","url":"https://api.github.com/users/cremor","html_url":"https://github.com/cremor","followers_url":"https://api.github.com/users/cremor/followers","following_url":"https://api.github.com/users/cremor/following{/other_user}","gists_url":"https://api.github.com/users/cremor/gists{/gist_id}","starred_url":"https://api.github.com/users/cremor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cremor/subscriptions","organizations_url":"https://api.github.com/users/cremor/orgs","repos_url":"https://api.github.com/users/cremor/repos","events_url":"https://api.github.com/users/cremor/events{/privacy}","received_events_url":"https://api.github.com/users/cremor/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Particular/NServiceBus/labels/Type:%20Discussion","name":"Type: Discussion","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-09-19T07:59:59Z","updated_at":"2016-09-22T10:54:00Z","closed_at":null,"body":"NServiceBus version 5.2.16\r\n\r\nAccording to the [container documentation page](http://docs.particular.net/nservicebus/containers/#using-an-existing-container-cleanup) we shouldn't dispose the bus instance manually but instead dispose the container. Quote:\r\n\r\n> Do NOT call IBus.Dispose when using an external container, instead call dispose in the container during shutdown.\r\n\r\nBut disposing the container seems to have various - sometimes big - problems.\r\n\r\nI've tested all available container samples as of today. In each sample I've removed the using block around the bus and added a call to `container.Dispose()` (or equivalent) as the last line of code. This are the results:\r\n\r\n- Autofac: Unhandled ObjectDisposedException in `MsmqDequeueStrategy.Stop()`\r\n- Castle: Unhandled ObjectDisposedException in `TransportReceiver.Stop()`\r\n- Ninject: Shows a warning about a ObjectDisposedException in `TimeoutPersisterReceiver.Poll()` and then hangs (deadlock?)\r\n- Spring: Shuts down, but logs an error about an InvalidOperationException in `AbstractApplicationContext.SafeGetObjectFactory()` (called indirectly from `FeatureActivator.StopFeatures()`)\r\n- StructureMap: Shuts down fine :smile: \r\n- Unity: Just hangs (deadlock?)\r\n\r\nI don't know if that note from the documentation page is still valid for NServiceBus 6 since the bus isn't injected in the container any more, but out of curiosity I also tried the Unity sample for NServiceBus 6 (Unity is the container I actually want to use). In that sample I replaced `endpointInstance.Stop()` with `container.Dispose()`.\r\n\r\nThis resulted in an InvalidOperationException thrown in `ExpiredTimeoutsPoller.Dispose()`."},"comment":{"url":"https://api.github.com/repos/Particular/NServiceBus/issues/comments/248869276","html_url":"https://github.com/Particular/NServiceBus/issues/4144#issuecomment-248869276","issue_url":"https://api.github.com/repos/Particular/NServiceBus/issues/4144","id":248869276,"user":{"login":"cremor","id":116314,"avatar_url":"https://avatars.githubusercontent.com/u/116314?v=3","gravatar_id":"","url":"https://api.github.com/users/cremor","html_url":"https://github.com/cremor","followers_url":"https://api.github.com/users/cremor/followers","following_url":"https://api.github.com/users/cremor/following{/other_user}","gists_url":"https://api.github.com/users/cremor/gists{/gist_id}","starred_url":"https://api.github.com/users/cremor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cremor/subscriptions","organizations_url":"https://api.github.com/users/cremor/orgs","repos_url":"https://api.github.com/users/cremor/repos","events_url":"https://api.github.com/users/cremor/events{/privacy}","received_events_url":"https://api.github.com/users/cremor/received_events","type":"User","site_admin":false},"created_at":"2016-09-22T10:54:00Z","updated_at":"2016-09-22T10:54:00Z","body":"In my case it is the end of the process, e.g. the `OnStop` method of an windows service.\r\nI think that's also what the current documentation means because the wording mentions \"shutdown\"."}}
{"actor":{"display_login":"cremor"}}