unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* print-circle, and backtraces containing circular structures causing infinite loop/out-of-memory
@ 2022-05-27  7:49 Adam Porter
  2022-05-27 12:32 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Adam Porter @ 2022-05-27  7:49 UTC (permalink / raw)
  To: emacs-devel

Hi,

In my work on Ement.el [0] over the past couple of years, I've gotten 
reports from users that Emacs would sometimes go into an infinite loop, 
using all available memory until it's exhausted.  I also observed this 
behavior myself at times.

I finally realized that this happened when an error was signaled and 
Emacs was trying to print a backtrace containing self-referential data 
structures (which Ement.el uses).  Then I set print-circle to t in my 
config, and the problem went away.  Then I suggested to users that they 
do the same, and it seems to have fixed the problem for them (those who 
have seen the suggestion in the readme).

Now, AFAICT it doesn't seem like setting print-circle to t is a good 
general-purpose solution.  For one thing, if it were, it would probably 
already be the default value.  As well, I suppose it might cause issues 
in other packages that print and read Lisp data.

So, my question: Is there a way to set print-circle only when printing 
backtraces?

I suppose I could try wrapping the highest level of my code's most 
common loop in a condition-case that binds print-circle before 
re-signaling the error, but it seems like Emacs ought to guard against 
this in all cases.  It's not likely that I could anticipate every place 
in my code where such a guard would need to be installed.

It seems like a potentially severe problem for Emacs to go into this 
infinite-loop/OOM condition, especially because it may happen when the 
user is not at the computer: the user can't notice and interrupt with 
"C-g", instead returning to an unresponsive, OOM system, or to find that 
the Emacs process was killed (in Ement.el's case, it tends to happen 
when an event arrives over the network that exposes a bug in Ement, like 
a malformed event, and the user may be AFK).

Thanks,
Adam

0: https://github.com/alphapapa/ement.el



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: print-circle, and backtraces containing circular structures causing infinite loop/out-of-memory
  2022-05-27  7:49 print-circle, and backtraces containing circular structures causing infinite loop/out-of-memory Adam Porter
@ 2022-05-27 12:32 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2022-05-27 12:32 UTC (permalink / raw)
  To: Adam Porter; +Cc: emacs-devel

> So, my question: Is there a way to set print-circle only when
> printing backtraces?

By sending a patch to debug(-early).el that does that?  I think so, yes.
:-)


        Stefan




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-27 12:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27  7:49 print-circle, and backtraces containing circular structures causing infinite loop/out-of-memory Adam Porter
2022-05-27 12:32 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).