Subject: Re: bug#16737: 24.3.50; Yank causes hang

From: Eli Zaretskii <[email-masked]>
Date: Tue, 04 Mar 2014 18:59:38 +0200

> From: Nicolas Richard <[email-masked]>
> Date: Tue, 04 Mar 2014 13:47:53 +0100
> Cc: [email-masked], Sujith Manoharan <[email-masked]>
> 
> Dmitry Antipov <[email-masked]> writes:
> > 1) It's better to attach gdb and try to obtain a backtrace, especially when
> > Emacs sits in CPU-eating loops.
> >
> > 2) If CPU-eating loop involves I/O (read/write/sendmsg/recvmsg/select/etc.),
> > try to understand how the relevant fds are used, by looking under
> > /proc/[Emacs PID]/fd directory. (In your log, the most important is fd 4;
> > probably this is an X socket).
> 
> I'm currently in a session which has the same problem. (This is not from
> emacs -Q, emacs-uptime reports almost 2 weeks of uptime.)
> 
> Evalling (x-get-selection) or (x-get-selection 'CLIPBOARD) with C-x C-e
> work fine but (x-get-selection 'SECONDARY) hangs for about 5 seconds (it
> seemed more before I started timing it... not sure if it's purely
> psychological). I then get a lisp bt:
> 
> Debugger entered--Lisp error: (error "Timed out waiting for reply from selection owner")
>   x-get-selection-internal(SECONDARY STRING)
>   x-get-selection(SECONDARY)
>   eval((x-get-selection (quote SECONDARY)) nil)
>   eval-last-sexp-1(nil)
>   eval-last-sexp(nil)
>   call-interactively(eval-last-sexp nil nil)
>   command-execute(eval-last-sexp)
> 
> During these 5 seconds, htop shows that emacs has almost 100% CPU usage.
> 
> Btw I also have bug #16925, which triggers debugger regularly.
> 
> Below is a gdb backtrace. I keep this emacs session open in case you
> want me to investigate more.

It looks like you attached GDB too late, the backtrace it shows is
after the busy loop, when Emacs already signaled an error and entered
the Lisp debugger.

Since you say that Emacs hangs for several seconds, would it be
possible for you to attach GDB right after you type C-x C-e to eval
(x-get-selection)?  You could prepare the "gdb -p PID" command line in
the shell window in advance, so all you'd need to type is RET.

Thanks.