{"action":"closed","issue":{"url":"https://api.github.com/repos/uber/tchannel-python/issues/115","labels_url":"https://api.github.com/repos/uber/tchannel-python/issues/115/labels{/name}","comments_url":"https://api.github.com/repos/uber/tchannel-python/issues/115/comments","events_url":"https://api.github.com/repos/uber/tchannel-python/issues/115/events","html_url":"https://github.com/uber/tchannel-python/issues/115","id":101307175,"number":115,"title":"uninitialized tchannel instance is not fork-safe","user":{"login":"blampe","id":848843,"avatar_url":"https://avatars.githubusercontent.com/u/848843?v=3","gravatar_id":"","url":"https://api.github.com/users/blampe","html_url":"https://github.com/blampe","followers_url":"https://api.github.com/users/blampe/followers","following_url":"https://api.github.com/users/blampe/following{/other_user}","gists_url":"https://api.github.com/users/blampe/gists{/gist_id}","starred_url":"https://api.github.com/users/blampe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blampe/subscriptions","organizations_url":"https://api.github.com/users/blampe/orgs","repos_url":"https://api.github.com/users/blampe/repos","events_url":"https://api.github.com/users/blampe/events{/privacy}","received_events_url":"https://api.github.com/users/blampe/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-08-16T22:56:36Z","updated_at":"2015-08-18T00:31:24Z","closed_at":"2015-08-18T00:31:24Z","body":"An uninitialized `TChannel` instance throws a future onto the ioloop, which then breaks forking.\r\n\r\n```python\r\n$ cat test.py\r\nimport os\r\n\r\nfrom tchannel import TChannel\r\n\r\nt = TChannel('app')\r\n\r\nprint 'forking'\r\n\r\nif os.fork() == 0:\r\n    t.listen()\r\n```\r\n\r\nAfter adding a print statement to `tornado.platform.kqueue:register`:\r\n\r\n```\r\n$ python test.py\r\nregistered a file descriptor\r\nforking\r\nregistered a file descriptor\r\nTraceback (most recent call last):\r\n  File \"test.py\", line 10, in <module>\r\n    t.listen()\r\n  File \"/Users/blampe/src/tchannel-python/tchannel/tchannel.py\", line 150, in listen\r\n    return self._dep_tchannel.listen(port)\r\n  File \"/Users/blampe/src/tchannel-python/tchannel/tornado/tchannel.py\", line 256, in listen\r\n    server.add_sockets(sockets)\r\n  File \"/Users/blampe/src/tchannel-python/env/lib/python2.7/site-packages/tornado/tcpserver.py\", line 144, in add_sockets\r\n    io_loop=self.io_loop)\r\n  File \"/Users/blampe/src/tchannel-python/env/lib/python2.7/site-packages/tornado/netutil.py\", line 266, in add_accept_handler\r\n    io_loop.add_handler(sock, accept_handler, IOLoop.READ)\r\n  File \"/Users/blampe/src/tchannel-python/env/lib/python2.7/site-packages/tornado/ioloop.py\", line 704, in add_handler\r\n    self._impl.register(fd, events | self.ERROR)\r\n  File \"/Users/blampe/src/tchannel-python/env/lib/python2.7/site-packages/tornado/platform/kqueue.py\", line 42, in register\r\n    self._control(fd, events, select.KQ_EV_ADD)\r\n  File \"/Users/blampe/src/tchannel-python/env/lib/python2.7/site-packages/tornado/platform/kqueue.py\", line 64, in _control\r\n    self._kqueue.control([kevent], 0)\r\nOSError: [Errno 9] Bad file descriptor\r\n```\r\n\r\nThe future is coming from `self.peers = PeerGroup(self)`, which initializes a `Peer` and creates a future in `self._reset_condition = Condition()`."}}