-
Notifications
You must be signed in to change notification settings - Fork 129
OSX Mavericks Process Killed on Fork #29
Comments
Pretty sure the issue is coming from this line https://github.com/coderanger/pychef/blob/master/chef/api.py#L195 We are not closing the connection at the end. For an example use case check out http://stackoverflow.com/questions/3880750/closing-files-properly-opened-with-urllib2-urlopen I will try to work out a PR soon. EDIT: Still working on this, did not seem to solve the problem by adding |
Digging deeper this seems to be a bug in import os
import urllib2
request = urllib2.urlopen('http://www.google.com')
response = rr.read()
request.close()
os.execvp('ssh', ['ssh', '[email protected]'])
Killed: 9 |
I am unable to produce the same error when using import os
import requests
response = requests.get('http://www.google.com')
os.execvp('ssh', ['ssh', '[email protected]'])
# Doesn't crash |
@andrewgross I wouldn't want to introduce a new dependency just for this given the current nebulous and unknown nature of things, but switching to both requests and cryptography will probably happen when I do a security overhaul on the SSL and signature code at some point. Thats a much bigger change though. |
That is unfortunate as I currently need the ability to Thanks |
@andrewgross For now you should be able to trivially subclass ChefAPI in your code and replace the usage of urllib2 :-) Just override that one hook method and use a different transport (such as requests). |
Just tried swapping out Potentially there are additional libraries causing bug while constructing / signing the request? |
Hmm, the background API stack in a thread local is certainly possible. If you manually clear that list out before forking does it help? (on a train so I can't get the code ref for you, the thread local is at the top of api.py though). |
If I take the headers and URL from PyChef and run them with |
@andrewgross Its probably either something in how I am using OpenSSL or how I keep resources in weakrefs on the threadlocal stack. |
Here is a gist of the changes I made to have Definitely some weird action at a distance stuff. The issue doesn't appear until I actually make the remote call. I can show the |
Can you post the diff too? Hard to see whats changed otherwise. |
I added the original as an edit to the first, so the ADD and DELETE are reversed, but should be helpful: https://gist.github.com/andrewgross/8922636/revisions Just to be clear, I only made this work for |
The workaround to the python bug I submitted fixes the issue for me: http://bugs.python.org/issue20585 I may still keep working on an alternate python chef implementation on the side. Mostly due to curiosity, but also because I got the RSA signing working with M2Crypto, which I feel was the harder part. Thanks for all the help. Edit: For anyone finding this if the link doesn't work, the fix is to run |
I have had this problem whilst using requests to systematically search through the free Twitter API search. It simply hangs:
I've just used Fix: |
Hey,
Discovered a nasty bug that only seems to manifest on the latest version of OSX, Mavericks, due to some additional security features they enabled.
The issue arises when you try to spawn a subprocess, or use
os
calls likeexecp
which replace your running process. It seems that when there are open remote connections, the python process has a file descriptor pointing a mac kernel queue so that it can receive events from the OS. This shows up inlsof -p $PID
as aKQUEUE
.This behavior is normal, but before running any of the fun OS process commands, the documentation warns us to flush
STDOUT
and close any open file handles as these would normally be inherited by the child process.Unfortunately, it seems that something about the way PyChef builds it's connections, is that it cannot clean them up properly in this use case. In the code where I discovered the bug, I used
boto
extensively but was unable to replicate the issue like I can below.When you trigger the bug, your process will exit, only stating
Killed: 9
in the terminal. In the Mac Console App you can see that the system log has... ssh: guarded fd exception: ...
and a link to a kernel dump.If you have a Mac with a fresh install of OSX Mavericks, you can replicate the bug with the following code:
I haven't had a change to dive in to the PyChef code to figure out where it is leaking connections (or perhaps some other event that it is subscribing to from the queue).
The text was updated successfully, but these errors were encountered: