New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFTPClient.stat freeze on concurrent invocation #718

Closed
idanarye opened this Issue Apr 3, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@idanarye

idanarye commented Apr 3, 2016

When trying to invoke stat on the same SFTP connection from multiple threads, Paramiko can get stuck(deadlock?). For example:

#!/usr/bin/python3

HOSTNAME =  # replace with your own
USERNAME =  # replace with your own
KEY_FILENAME =  # replace with your own

from threading import Thread

from paramiko import SSHClient, AutoAddPolicy

ssh = SSHClient()
ssh.set_missing_host_key_policy(AutoAddPolicy())
ssh.connect(hostname=HOSTNAME, username=USERNAME, key_filename=KEY_FILENAME)

sftp = ssh.open_sftp()

def print_root_stat(caption):
    print(caption, '\t', 'stat:', sftp.stat('/'))

print_root_stat('Main thread')

threads = [Thread(group=None, target=print_root_stat, args=('Thread %s' % i,), daemon=False) for i in range(10)]
for thread in threads:
    thread.start()

When I run this I get:

Main thread      stat: dr-xr-xr-x   1 0        0            4096 03 Apr 13:51 ?
Thread 1         stat: dr-xr-xr-x   1 0        0            4096 03 Apr 13:51 ?
Thread 2         stat: dr-xr-xr-x   1 0        0            4096 03 Apr 13:51 ?

And that's it(it's always different threads that manage to run).

Does Paramiko's SFTP even supposed to support concurrency? Looking at the code it seems like it should, but I didn't see no such promise in the docs...

@bitprophet

This comment has been minimized.

Member

bitprophet commented Apr 25, 2016

Suspect this falls under #578, which deals with threading locks & the SFTP client code. That should get merged and released soon. Please reopen this if nabbing a new release after that ticket gets resolved, doesn't fix your situation. Thanks!

@bitprophet bitprophet closed this Apr 25, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment