{"action":"created","issue":{"url":"https://api.github.com/repos/Netflix/Hystrix/issues/346","labels_url":"https://api.github.com/repos/Netflix/Hystrix/issues/346/labels{/name}","comments_url":"https://api.github.com/repos/Netflix/Hystrix/issues/346/comments","events_url":"https://api.github.com/repos/Netflix/Hystrix/issues/346/events","html_url":"https://github.com/Netflix/Hystrix/issues/346","id":50289893,"number":346,"title":"HystrixMetricsStreamServlet.destroy() not invoked until container timeout","user":{"login":"codependent","id":6399869,"avatar_url":"https://avatars.githubusercontent.com/u/6399869?v=3","gravatar_id":"","url":"https://api.github.com/users/codependent","html_url":"https://github.com/codependent","followers_url":"https://api.github.com/users/codependent/followers","following_url":"https://api.github.com/users/codependent/following{/other_user}","gists_url":"https://api.github.com/users/codependent/gists{/gist_id}","starred_url":"https://api.github.com/users/codependent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codependent/subscriptions","organizations_url":"https://api.github.com/users/codependent/orgs","repos_url":"https://api.github.com/users/codependent/repos","events_url":"https://api.github.com/users/codependent/events{/privacy}","received_events_url":"https://api.github.com/users/codependent/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Netflix/Hystrix/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2014-11-27T13:11:15Z","updated_at":"2015-01-21T13:03:09Z","closed_at":null,"body":"__Scenario:__\r\n1. JEE App with hystrix + hystrix-metrix-event-stream (v1.3.18). \r\n2. Hystrix dashboard requesting data to the App.\r\n3. When we stop App in our server we see that the following loop doesn't stop: \r\n\r\n    HystrixMetricsStreamServlet.handleRequest(){\r\n    ...  \r\n       while (poller.isRunning() && !isDestroyed) {\r\n\r\nThe servlet's destroy() method is not called, thus **isDestroyed is not modified until timeout**. This makes sense since, according to the servlet spec: *void destroy() - Called by [...] This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed.*\r\n\r\nThe problem is that since there is a running request, whenever we want to republish/stop our application, we have to wait 60 seconds until our container (Websphere Application Server 8) forces the destruction of the servlet."},"comment":{"url":"https://api.github.com/repos/Netflix/Hystrix/issues/comments/70832804","html_url":"https://github.com/Netflix/Hystrix/issues/346#issuecomment-70832804","issue_url":"https://api.github.com/repos/Netflix/Hystrix/issues/346","id":70832804,"user":{"login":"codependent","id":6399869,"avatar_url":"https://avatars.githubusercontent.com/u/6399869?v=3","gravatar_id":"","url":"https://api.github.com/users/codependent","html_url":"https://github.com/codependent","followers_url":"https://api.github.com/users/codependent/followers","following_url":"https://api.github.com/users/codependent/following{/other_user}","gists_url":"https://api.github.com/users/codependent/gists{/gist_id}","starred_url":"https://api.github.com/users/codependent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codependent/subscriptions","organizations_url":"https://api.github.com/users/codependent/orgs","repos_url":"https://api.github.com/users/codependent/repos","events_url":"https://api.github.com/users/codependent/events{/privacy}","received_events_url":"https://api.github.com/users/codependent/received_events","type":"User","site_admin":false},"created_at":"2015-01-21T13:03:09Z","updated_at":"2015-01-21T13:03:09Z","body":"I'd like to point out one important thing: jboyd01 suggested using another servlet's destroy() to invoke `HystrixMetricsStreamServlet.shutdown()` but **this won't work** under Websphere. \r\n\r\nThe reason is that WS doesn't invoke any servlet.destroy() until all requests have finished. Yet, it does destroy JSPs (which is a kind of servlet, WTH?)\r\n\r\nThe only way I found to invoke `HystrixMetricsStreamServlet.shutdown()` is through a startup bean EJB. As simple as this:\r\n```\r\nimport javax.annotation.PostConstruct;\r\nimport javax.annotation.PreDestroy;\r\nimport javax.ejb.Singleton;\r\nimport javax.ejb.Startup;\r\n\r\nimport com.netflix.hystrix.Hystrix;\r\nimport com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;\r\n\r\n@Singleton\r\n@Startup\r\npublic class HystrixStopper {\r\n\r\n\t@PostConstruct\r\n\tpublic void init(){\r\n\t\tSystem.out.println(\"init\");\r\n\t}\r\n\t\r\n\t@PreDestroy\r\n\tpublic void preDestroy(){\r\n\t\t//Stops the metrics servlet\r\n\t\tHystrixMetricsStreamServlet.shutdown();\r\n\t\t//Shuts down all threads started by Hystrix\r\n\t\tHystrix.reset();\r\n\t}\r\n}\r\n```"}}