_libssh2_channelfree is called from session.__dealloc__ and from channel.__dealloc_\ creating race condition if these guys called simultaneously, while free_state is not doing what it suppose to do.
Steps to reproduce:
Python 3.8.
Create lots of connections in multiple (10>) threads
Additional info: [Include version of libssh2 and any other relevant information.]
Bug reports
After upgrading to python 3.8 started to get double free.
Caused by no nogil at session and channel __dealloc__: https://github.com/ParallelSSH/ssh2-python/blob/e5fdd3e8e60e4984d87fa0673d7de5b86a154323/ssh2/channel.pyx#L38-L42 https://github.com/ParallelSSH/ssh2-python/blob/e5fdd3e8e60e4984d87fa0673d7de5b86a154323/ssh2/session.pyx#L60-L64 and/or wrong free_state implementation in _libssh2_channel_free: https://github.com/ParallelSSH/ssh2-python/blob/e5fdd3e8e60e4984d87fa0673d7de5b86a154323/libssh2/src/channel.c#L2477-L2553
Commit that brought the bug in: https://github.com/ParallelSSH/ssh2-python/search?q=a3d077ec6370a870a463ddb3dbafc9bf0f5dc11a&type=Commits
_libssh2_channelfree is called from session.__dealloc__ and from channel.__dealloc_\ creating race condition if these guys called simultaneously, while free_state is not doing what it suppose to do.
Steps to reproduce:
Additional info: [Include version of
libssh2
and any other relevant information.]OS: Ubuntu 20.04 LTS libssh2: libssh2-1/focal,now 1.8.0-2.1build1 amd64 [installed] ssh2-python: 0.18.0.post1
Coredump: PID: 478136 (python) UID: 1000 () GID: 1000 (() Signal: 6 (ABRT) Timestamp: Tue 2020-07-07 18:56:22 +07 (15h ago) Command Line: /usr/src/scylladb/scylla-cluster-tests/venv/bin/python /snap/pycharm-professional/201/plugins/python/helpers/pycharm/_jb_unittest_runner.py --target test_remoter.TestRemoteCmdRunners Executable: /usr/bin/python3.8 Control Group: /user.slice/user-1000.slice/user@1000.service/gnome-launched-pycharm-professional_pycharm-professional.desktop-2141.scope Unit: user@1000.service User Unit: gnome-launched-pycharm-professional_pycharm-professional.desktop-2141.scope Slice: user-1000.slice Owner UID: 1000 () Boot ID: bf46036b244c4892bda38eb554c597e8 Machine ID: 8d0016f80e894e3b9dd46b4151a24456 Hostname: Storage: /var/lib/systemd/coredump/core.python.1000.bf46036b244c4892bda38eb554c597e8.478136.1594122982000000000000.lz4 Message: Process 478136 (python) of user 1000 dumped core.
Full backtrace: ssh2-python.zip