From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.devel Subject: print-circle, and backtraces containing circular structures causing infinite loop/out-of-memory Date: Fri, 27 May 2022 02:49:24 -0500 Message-ID: <2a1a210a-57f2-2d51-d921-c96148e3c955@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8061"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri May 27 09:52:30 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nuUlo-0001un-Pw for ged-emacs-devel@m.gmane-mx.org; Fri, 27 May 2022 09:52:29 +0200 Original-Received: from localhost ([::1]:49992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nuUln-0004mi-0i for ged-emacs-devel@m.gmane-mx.org; Fri, 27 May 2022 03:52:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nuUix-0003rC-Rg for emacs-devel@gnu.org; Fri, 27 May 2022 03:49:33 -0400 Original-Received: from hedgehog.birch.relay.mailchannels.net ([23.83.209.81]:27244) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nuUiv-0003ax-Ot for emacs-devel@gnu.org; Fri, 27 May 2022 03:49:31 -0400 X-Sender-Id: dreamhost|x-authsender|inbox@alphapapa.net Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 98DC8C1D8A for ; Fri, 27 May 2022 07:49:26 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a295.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 38338C1C7D for ; Fri, 27 May 2022 07:49:26 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1653637766; a=rsa-sha256; cv=none; b=ytW4l58kdt3yL0wvw/hA3QtU+mo8KRnDqWqw9vsq5C0Ee5f1sw+vLfirl0cnprCr1VQ0Xs 4AMXUzhNq55JsxK7s9mIDZbxfmntsdeFVGVWzHAunfsBwN5vhUAT8WY5ann/vmp59EW4Ep +xnx5NrqYVpdpLr+e9t4F/3ZxeyFJz50xsnPQEcDE26mEF5u6jfdSxYGbrv0DPm1LpmQrk lKAFCewhtO6GLGf7DYKkD4mL6tjzOdZfLBVJ5LIp8zkoBWjI7lo4V0H+38SelRaYQAVuR1 vwwGelPIVeNXNc2CcbgNp6QtYPw2AzjgsKa4Mqh21YU2E/gOUYIV4Dge2JF+Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1653637766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:dkim-signature; bh=ynBPPhm0Ghy9t6QIASPx/TdqcxKxEC+w/bbLu9Rf9YM=; b=tUzVLyZMIVVte4w+Wg8n/3gjyoJzjSUqaVImhF9emy1LvgdTtZ/OXv6Xl+l6gFcjQIHBLQ dvPs4UQZkdI4/7UIe1ORjMCGX/Y4mc3uk9UfBc+B6kdJCYA1vBuUUvWBOx6jVYAco+Fj7g IiBkkO14IMw3MZNCxQ8hhp7ckXr7Hu4Xb6K01CGYT+JpGXOzKPdZGD3K+ziRD3t0KgCW1a QqLsjyqKB7NyT3GCjazZgA5XFNQmnXZdI/Cm5u5g80n+ZsatJrl49OQCr2qyc+UUP7ujrm gSTSB86368c1aKGaXNsDLeHtw6TidvBERcSrwAi1RJEERs81b7BKg6w+BjMKAw== ARC-Authentication-Results: i=1; rspamd-68cf9fd8bf-jjzj6; auth=pass smtp.auth=dreamhost smtp.mailfrom=adam@alphapapa.net X-Sender-Id: dreamhost|x-authsender|inbox@alphapapa.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|inbox@alphapapa.net X-MailChannels-Auth-Id: dreamhost X-Belong-Invention: 5d89acbd64252181_1653637766436_1350106828 X-MC-Loop-Signature: 1653637766436:3518821432 X-MC-Ingress-Time: 1653637766436 Original-Received: from pdx1-sub0-mail-a295.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.101.255.183 (trex/6.7.1); Fri, 27 May 2022 07:49:26 +0000 Original-Received: from [10.48.0.46] (unknown [45.131.192.13]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: inbox@alphapapa.net) by pdx1-sub0-mail-a295.dreamhost.com (Postfix) with ESMTPSA id 4L8cQF5fZlz1Fx for ; Fri, 27 May 2022 00:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alphapapa.net; s=dreamhost; t=1653637766; bh=ynBPPhm0Ghy9t6QIASPx/TdqcxKxEC+w/bbLu9Rf9YM=; h=Date:To:From:Subject:Content-Type:Content-Transfer-Encoding; b=R3Cyoi+eiWppPdZBAacmSa4/Cw74uF7pfc2iblKZaGqRwPO4ryW1bCrzjZpjzUtHB mk2BhHe/f2kMLlUmcbU9f4XJQNhmXtnvGJQ+7tFrBVxtaBVj/dtA6xtQHIHnNPPrRr u1VVM+4qsK/fmfaIsnSsHDTcrrlPas5xcrofnZ/Q22I+N6Ac0tMdAXphOlBJ/W4F4A CxjROIU2o3v+N5j5Y5wIkje7RYcGqouPwuOvoGr6a0fLoyvrfrhRrZyvKL/zFuniIL dY3h6mbssOnfvQlicCWTU5V9izCykSyn9K6GyG4L9ZYQ+kPXAwk8kN67XrivqQhWQc hqFOKUhLpgwgQ== Content-Language: en-US Received-SPF: neutral client-ip=23.83.209.81; envelope-from=adam@alphapapa.net; helo=hedgehog.birch.relay.mailchannels.net X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:290295 Archived-At: 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