{"action":"created","issue":{"url":"https://api.github.com/repos/zeromq/jeromq/issues/302","labels_url":"https://api.github.com/repos/zeromq/jeromq/issues/302/labels{/name}","comments_url":"https://api.github.com/repos/zeromq/jeromq/issues/302/comments","events_url":"https://api.github.com/repos/zeromq/jeromq/issues/302/events","html_url":"https://github.com/zeromq/jeromq/issues/302","id":117883287,"number":302,"title":"Intermittent NullPointerException and hang when terminating context","user":{"login":"hiteshjasani","id":6628,"avatar_url":"https://avatars.githubusercontent.com/u/6628?v=3","gravatar_id":"","url":"https://api.github.com/users/hiteshjasani","html_url":"https://github.com/hiteshjasani","followers_url":"https://api.github.com/users/hiteshjasani/followers","following_url":"https://api.github.com/users/hiteshjasani/following{/other_user}","gists_url":"https://api.github.com/users/hiteshjasani/gists{/gist_id}","starred_url":"https://api.github.com/users/hiteshjasani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hiteshjasani/subscriptions","organizations_url":"https://api.github.com/users/hiteshjasani/orgs","repos_url":"https://api.github.com/users/hiteshjasani/repos","events_url":"https://api.github.com/users/hiteshjasani/events{/privacy}","received_events_url":"https://api.github.com/users/hiteshjasani/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-11-19T19:00:41Z","updated_at":"2016-01-13T17:38:42Z","closed_at":null,"body":"Hey, when running jeromq 0.3.5 I'm seeing an intermittent hang when terminating the context.  Sometimes when it hangs, it also prints out an exception.\r\n\r\n```\r\nException in thread \"reaper-1\" java.lang.NullPointerException\r\n        at zmq.Pipe.processPipeTermAck(Pipe.java:396)\r\n        at zmq.ZObject.processCommand(ZObject.java:97)\r\n        at zmq.SocketBase.processCommands(SocketBase.java:863)\r\n        at zmq.SocketBase.inEvent(SocketBase.java:968)\r\n        at zmq.Poller.run(Poller.java:247)\r\n        at java.lang.Thread.run(Thread.java:745)\r\n```\r\n\r\nMy code is actually in clojure, but it is creating a `ZMQ$Context` object and then calling the `.term()` method on it when the problem happens.  By the time I'm trying to terminate the context, the sockets are already closed.  I've also tried unregistering the socket from the poller before closing it, but it didn't make any difference.\r\n\r\nSince this occurs on shutting down my app it's not critical, but I kinda want to make sure no resources are leaking."},"comment":{"url":"https://api.github.com/repos/zeromq/jeromq/issues/comments/171374892","html_url":"https://github.com/zeromq/jeromq/issues/302#issuecomment-171374892","issue_url":"https://api.github.com/repos/zeromq/jeromq/issues/302","id":171374892,"user":{"login":"ThunderSOS","id":16688674,"avatar_url":"https://avatars.githubusercontent.com/u/16688674?v=3","gravatar_id":"","url":"https://api.github.com/users/ThunderSOS","html_url":"https://github.com/ThunderSOS","followers_url":"https://api.github.com/users/ThunderSOS/followers","following_url":"https://api.github.com/users/ThunderSOS/following{/other_user}","gists_url":"https://api.github.com/users/ThunderSOS/gists{/gist_id}","starred_url":"https://api.github.com/users/ThunderSOS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThunderSOS/subscriptions","organizations_url":"https://api.github.com/users/ThunderSOS/orgs","repos_url":"https://api.github.com/users/ThunderSOS/repos","events_url":"https://api.github.com/users/ThunderSOS/events{/privacy}","received_events_url":"https://api.github.com/users/ThunderSOS/received_events","type":"User","site_admin":false},"created_at":"2016-01-13T17:38:42Z","updated_at":"2016-01-13T17:38:42Z","body":"Doing a sleep() before closing the Context, the sockets have already been requested to shut down, seems to work for me too so this may be a clue to a fix. \r\nThe shut down sequence looks like this: \r\n\r\n2016-01-13 17:28:35,926 [INFO] MessageSubscriberWorker - Shutting down MessageWorker\r\n2016-01-13 17:28:35,926 [DEBUG] MessageSubscriberWorker - Thread interrupted\r\n2016-01-13 17:28:35,927 [INFO] MessageSubscriberWorker - MessageWorker thread exited\r\n2016-01-13 17:28:35,927 [INFO] .MessageSubscriberService - Closing MessageSubscriber \r\n2016-01-13 17:28:35,927 [DEBUG] zmq.ZmqMessageSubscriber - Disconnecting ZMQ socket\r\n2016-01-13 17:28:35,928 [INFO] MessageSubscriberService - Shutting down Subscriber thread\r\n2016-01-13 17:28:35,928 [INFO] zmq.ZmqContextHolder - Wait 2 seconds then close context. Closing ZMQ context\r\n\r\nTypically the server got stuck at the last line until a wait was added. Bit of a nasty fix (how long is long enough?) but it seems to work. "}}