[ 
https://issues.apache.org/jira/browse/GUACAMOLE-1115?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17508379#comment-17508379
 ] 

Mike Jumper commented on GUACAMOLE-1115:
----------------------------------------

The issue is due to deadlock between three threads: the thread handling inbound 
instructions from the user (such as “mouse” and “ack”), the thread handling 
data received from the RDP server, and the thread handling the print job.

||*Guacamole input thread*||*RDP client thread*||*RDP print thread*||
| | |Wait for receipt of “ack” from Guacamole client|
| |Lock {{message_lock}} (success)| |
| |Enter {{freerdp_check_event_handles()}}| |
|Enter {{guac_rdp_user_mouse_handler()}}| | |
|Lock {{message_lock}} (blocked - held by RDP client thread)| | |
| |Enter {{guac_rdp_print_job_free()}}| |
| |Join RDP print thread (blocked - “ack” not yet received)| |

This is deadlock:

 * The handler for the “mouse” instruction cannot proceed because it’s waiting 
for {{{}message_lock{}}}.
 * The {{message_lock}} cannot be released because it needs to be held while 
RDP events are being handled by {{{}freerdp_check_event_handles(){}}}.
 * {{freerdp_check_event_handles()}} cannot proceed because it needs to finish 
handling the closure of the print job.
 * The print job cannot be closed because the print output thread needs to 
finish.
 * The print output thread cannot finish because it’s still waiting for the 
“ack” instruction.
 * The “ack” instruction cannot be read and handled because the “mouse” 
instruction was received first and has not yet finished being handled.

We will need to modify the way print jobs are closed to allow the background 
handling of that job, the filter process, etc. to remain until everything is 
truly complete.

> RDP print process may hang
> --------------------------
>
>                 Key: GUACAMOLE-1115
>                 URL: https://issues.apache.org/jira/browse/GUACAMOLE-1115
>             Project: Guacamole
>          Issue Type: Bug
>          Components: guacamole-server
>    Affects Versions: 1.1.0
>            Reporter: Jimmy
>            Priority: Minor
>
> I found the printing problem that locks up the entire session and produces 
> the disconnect.
> When connecting the Windows 2010 and printing the document in Microsoft Word, 
> I encountered this problem.
> This problem isn't always produced and it's sometimes produced.
>  
> So, I have analyzed the printing part of the guacamole server project.
> I have found the following issue:
> If *guac_rdp_print_job_set_state()* function is called after 
> *guac_rdp_print_job_wait_for_ack()* call, this produces the lock of the 
> entire session.
>  
> {code:java}
> static void guac_rdp_print_job_set_state(guac_rdp_print_job* job,
>         guac_rdp_print_job_state state) {
>     pthread_mutex_lock(&(job->state_lock));
>     /* Update stream state, signalling modification */
>     job->state = state;
>     pthread_cond_signal(&(job->state_modified));
>     pthread_mutex_unlock(&(job->state_lock));
> }
> {code}
>   
> {code:java}
> static int guac_rdp_print_job_wait_for_ack(guac_rdp_print_job* job) {
>     /* Wait for ack if stream open and not yet received */
>     pthread_mutex_lock(&(job->state_lock));
>     if (job->state == GUAC_RDP_PRINT_JOB_WAITING_FOR_ACK)
>         pthread_cond_wait(&job->state_modified, &job->state_lock);
>     /* Reset state if ack received */
>     int got_ack = (job->state == GUAC_RDP_PRINT_JOB_ACK_RECEIVED);
>     if (got_ack)
>         job->state = GUAC_RDP_PRINT_JOB_WAITING_FOR_ACK;
>     /* Return whether ack was successfully received */
>     pthread_mutex_unlock(&(job->state_lock));
>     return got_ack;
> }
> {code}
>   
> I think that this issue can produce a printing problem and a lock of the 
> entire session.
> Please let me know whether my thought is correct.
>  
> Thanks.
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to