Github user sanhex commented on a diff in the pull request:

    
https://github.com/apache/incubator-guacamole-server/pull/118#discussion_r145826455
  
    --- Diff: src/protocols/ssh/client.c ---
    @@ -70,8 +70,14 @@ int guac_ssh_client_free_handler(guac_client* client) {
     
         /* Free terminal (which may still be using term_channel) */
         if (ssh_client->term != NULL) {
    -        guac_terminal_free(ssh_client->term);
    +        /* Close user input pipe to stop reading in ssh_input_thread */
    +        close(ssh_client->term->stdin_pipe_fd[1]);
    +        close(ssh_client->term->stdin_pipe_fd[0]);
    +        ssh_client->term->stdin_pipe_fd[1] = -1;
    +        ssh_client->term->stdin_pipe_fd[0] = -1;
    +
    --- End diff --
    
    I agree this looks really ugly. But if I don't close the pipe here, there 
will be a dead lock in this case.
    
    The thread here will be waiting for ssh_client_thread() by calling 
pthread_join(ssh_client->client_thread, NULL), ssh_client_thread() will be 
waiting for ssh_input_thread(). ssh_input_thread() will be blocked by 
guac_terminal_read_stdin() show below.
    
https://github.com/sanhex/incubator-guacamole-server/blob/c6cb1910e3580f9c21fc202f824fc55c95a43e49/src/protocols/ssh/ssh.c#L161
    
    The child process of guacd will never exit after disconnecting the ssh 
connection. I met this problem.. So I manually closed the pipe to stop the 
ssh_input_thread() mentioned above.


---

Reply via email to