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

Hanging Issue #294

Open
fatalkam opened this issue Sep 6, 2017 · 2 comments
Open

Hanging Issue #294

fatalkam opened this issue Sep 6, 2017 · 2 comments

Comments

@fatalkam
Copy link

fatalkam commented Sep 6, 2017

I have a project that is multi threaded running about 8 threads. Most of the ssh calls are very short calls looking for files, verifying size, doing a delete here and there though the process. However on calls that are compressing the file which can take up to 45+ minutes the task gets stuck on execute.

It never gets a response back so I can not confirm it was completed. It does not happen all the time and i am not sure what to do next. I get no error just hangs on move_tar_result = move_tar_file.Execute().

I have asked if there were max connections or a timeout and the system admin said no. Maybe there is a better way?

 Using client = New SshClient(My.Resources.ssh_host, My.Resources.ssh_user, My.Resources.ssh_pwd)
            client.Connect()
            client.KeepAliveInterval = New TimeSpan(0, 0, 5)
            Dim move_tar_file = client.RunCommand("/bin/tar -czvf " & destination_path & "/" & file_name & ".tgz -C " & source_path & "/ " & file_name)
            Dim move_tar_result = move_tar_file.Execute()
            Dim move_tar_response = ssh_response(move_tar_file, move_tar_result, "DEBUG: Moving File and Taring File")

            If move_tar_response.Contains("/bin/tar: Exiting with failure status due to previous errors") Then
                file_result = False
            Else
                set_file_permission(destination_path & "/" & file_name & ".tgz")
                file_result = True
            End If

            client.Disconnect()
        End Using
@fatalkam
Copy link
Author

I figured I would update this thread as I changed the code some. Smaller compress files seem to work fine still but on larger ones that take a hour or more still get hung. With this code it stops on reader.readline.

` Dim out_response As New List(Of String)

    Using client = New SshClient(host, username, password)
        client.Connect()

        Dim cmd = client.CreateCommand("/bin/tar -czvf " & destination_path & "/" & file_name & ".tgz -C " & source_path & "/ " & file_name)
        Dim asynch = cmd.BeginExecute()

        Dim reader = New StreamReader(cmd.ExtendedOutputStream)

        While Not asynch.IsCompleted
            If client.IsConnected = False Then
                Console.WriteLine("Connection Closed")
                Return False
            End If

            Dim result = reader.ReadLine()

            If Not String.IsNullOrEmpty(cmd.Error) Then
                out_response.Add(cmd.Error)
            End If

            If result IsNot Nothing Then
                out_response.Add(result)
            End If
        End While
        cmd.EndExecute(asynch)
        client.Disconnect()

    End Using`

@drieseng
Copy link
Member

drieseng commented Sep 10, 2017

The streams exposed by SshCommand really need to be revisited.
I don't have time to look into it right now, but this is something we need to take care of in the next release (2017.0.0). PR #13 and #144 describe some issues.

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

2 participants