Skip to content

Deadlock in InternalUploadFile #957

Closed
@katsela

Description

@katsela

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions