Skip to content
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

Deadlock in InternalUploadFile #957

Open
katsela opened this issue May 7, 2022 · 0 comments
Open

Deadlock in InternalUploadFile #957

katsela opened this issue May 7, 2022 · 0 comments

Comments

@katsela
Copy link

katsela commented May 7, 2022

I went through SftpClient briefly and I noticed that the reset event is only set when s.StatusCode == StatusCodes.Ok

_sftpSession.RequestWrite(handle, offset, buffer, 0, bytesRead, null, s =>
                        {
                            if (s.StatusCode == StatusCodes.Ok)
                            {
                                Interlocked.Decrement(ref expectedResponses);
                                responseReceivedWaitHandle.Set();

                                //  Call callback to report number of bytes written
                                if (uploadCallback != null)
                                {
                                    //  Execute callback on different thread
                                    ThreadAbstraction.ExecuteThread(() => uploadCallback(writtenBytes));
                                }
                            }
                        });

which means that
once loop reaches

//  Wait for expectedResponses to change 
_sftpSession.WaitOnHandle(responseReceivedWaitHandle, _operationTimeout);

and status code for all write requests != StatusCodes.Ok the loop will hang

This is not just observation I've seen it happen many times, this results in thread starvation for the host application eventually.

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant