{"action":"created","issue":{"url":"https://api.github.com/repos/pyca/cryptography/issues/1868","labels_url":"https://api.github.com/repos/pyca/cryptography/issues/1868/labels{/name}","comments_url":"https://api.github.com/repos/pyca/cryptography/issues/1868/comments","events_url":"https://api.github.com/repos/pyca/cryptography/issues/1868/events","html_url":"https://github.com/pyca/cryptography/issues/1868","id":71056952,"number":1868,"title":"TypeError exception (FFI related) when used in a multi threaded environment","user":{"login":"uri247","id":818607,"avatar_url":"https://avatars.githubusercontent.com/u/818607?v=3","gravatar_id":"","url":"https://api.github.com/users/uri247","html_url":"https://github.com/uri247","followers_url":"https://api.github.com/users/uri247/followers","following_url":"https://api.github.com/users/uri247/following{/other_user}","gists_url":"https://api.github.com/users/uri247/gists{/gist_id}","starred_url":"https://api.github.com/users/uri247/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uri247/subscriptions","organizations_url":"https://api.github.com/users/uri247/orgs","repos_url":"https://api.github.com/users/uri247/repos","events_url":"https://api.github.com/users/uri247/events{/privacy}","received_events_url":"https://api.github.com/users/uri247/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-26T11:55:20Z","updated_at":"2015-04-26T12:39:59Z","closed_at":null,"body":"I'm getting the following exception:\r\n\r\n```\r\n  File \".../hazmat/primitives/serialization.py\", line 20, in load_pem_private_key\r\n    return backend.load_pem_private_key(data, password)\r\n  File \".../hazmat/backends/multibackend.py\", line 276, in load_pem_private_key\r\n    return b.load_pem_private_key(data, password)\r\n  File \".../hazmat/backends/openssl/backend.py\", line 691, in load_pem_private_key\r\n    password,\r\n  File \".../hazmat/backends/openssl/backend.py\", line 831, in _load_key\r\n    self._ffi.NULL\r\nTypeError: initializer for ctype 'int(*)(char *, int, int, void *)' must be a pointer to same type, not cdata 'int(*)(char *, int, int, void *)'\r\n```\r\n\r\nThe exception isn't deterministic, but it is guaranteed to happen after a short while. I'm running from a wsgi module within apache (mod_apache). I'm running cryptography 0.8.2\r\n\r\nThe code that I'm running is:\r\n\r\n```python\r\nimport cryptography.hazmat.backends\r\nimport cryptography.hazmat.primitives.serialization\r\n\r\nwith open(my_pem_file, 'rb') as f:\r\n    pem = f.read()\r\n\r\npkey = cryptography.hazmat.primitives.serialization.load_pem_private_key(\r\n    pem, password=None, backend=cryptography.hazmat.backends.default_backend())\r\n```\r\n\r\nFrom logs on the calling module, I'm learning that it when it happens it is always the first time I'm calling `load_pem_private_key` *from a new thread*.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pyca/cryptography/issues/comments/96373802","html_url":"https://github.com/pyca/cryptography/issues/1868#issuecomment-96373802","issue_url":"https://api.github.com/repos/pyca/cryptography/issues/1868","id":96373802,"user":{"login":"uri247","id":818607,"avatar_url":"https://avatars.githubusercontent.com/u/818607?v=3","gravatar_id":"","url":"https://api.github.com/users/uri247","html_url":"https://github.com/uri247","followers_url":"https://api.github.com/users/uri247/followers","following_url":"https://api.github.com/users/uri247/following{/other_user}","gists_url":"https://api.github.com/users/uri247/gists{/gist_id}","starred_url":"https://api.github.com/users/uri247/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uri247/subscriptions","organizations_url":"https://api.github.com/users/uri247/orgs","repos_url":"https://api.github.com/users/uri247/repos","events_url":"https://api.github.com/users/uri247/events{/privacy}","received_events_url":"https://api.github.com/users/uri247/received_events","type":"User","site_admin":false},"created_at":"2015-04-26T12:39:59Z","updated_at":"2015-04-26T12:39:59Z","body":"Thank you for replying so fast.\r\n\r\nYes, switching to openssl.backend also reproduce the same bug. It only short circuit the line 'multibackend' (obviously) and from serialization.py the trace goes directly to openssl/backend.py\r\n\r\n```\r\nFile \"/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/serialization.py\", line 20, in load_pem_private_key\r\n    return backend.load_pem_private_key(data, password)\r\n  File \"/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/openssl/backend.py\", line 691, in load_pem_private_key\r\n    password,\r\n  File \"/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/openssl/backend.py\", line 831, in _load_key\r\n    self._ffi.NULL\r\nTypeError: initializer for ctype 'int(*)(char *, int, int, void *)' must be a pointer to same type, not cdata 'int(*)(char *, int, int, void *)'\r\n```"}}