From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "J.P." Newsgroups: gmane.emacs.bugs Subject: bug#50007: 28.0.50; normalize logic surrounding erc-server-reconnecting Date: Sat, 06 Nov 2021 01:49:00 -0700 Message-ID: <87pmrd7jpf.fsf@neverwas.me> References: <87a6lojcij.fsf@neverwas.me> <87sfwaav0l.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12938"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux) Cc: 50007@debbugs.gnu.org, Amin Bandali To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 06 09:50:22 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1mjHOz-00033F-6L for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Nov 2021 09:50:17 +0100 Original-Received: from localhost ([::1]:35462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjHOx-0006bM-8a for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Nov 2021 04:50:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjHOk-0006bC-LN for bug-gnu-emacs@gnu.org; Sat, 06 Nov 2021 04:50:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjHOk-000143-D3 for bug-gnu-emacs@gnu.org; Sat, 06 Nov 2021 04:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mjHOk-0003Qw-Bc for bug-gnu-emacs@gnu.org; Sat, 06 Nov 2021 04:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "J.P." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Nov 2021 08:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50007 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 50007-submit@debbugs.gnu.org id=B50007.163618855813141 (code B ref 50007); Sat, 06 Nov 2021 08:50:02 +0000 Original-Received: (at 50007) by debbugs.gnu.org; 6 Nov 2021 08:49:18 +0000 Original-Received: from localhost ([127.0.0.1]:48331 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjHO1-0003Pt-Hd for submit@debbugs.gnu.org; Sat, 06 Nov 2021 04:49:18 -0400 Original-Received: from mail-108-mta252.mxroute.com ([136.175.108.252]:33213) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjHNy-0003Pf-R6 for 50007@debbugs.gnu.org; Sat, 06 Nov 2021 04:49:15 -0400 Original-Received: from filter004.mxroute.com ([149.28.56.236] filter004.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta252.mxroute.com (ZoneMTA) with ESMTPSA id 17cf46fda5f0000b55.001 for <50007@debbugs.gnu.org> (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Sat, 06 Nov 2021 08:49:03 +0000 X-Zone-Loop: f241a3d966872d2cd64eafff3572a581b85e720da96e X-Originating-IP: [149.28.56.236] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=neverwas.me ; s=x; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References: Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=brIXWQCc4shdPI4jqs+cz1r4BoFmlH7tYxmoEAK1XCc=; b=fa9NSfVzUZvQAKhM+EoyoZekbe Uhl0cwh1s0xjl+Cq5dWaWI3ExPinAdLC2swU8jLQB82SNWKxrH7Zi2HaDyyRY4/N3xAbIhM8va52/ CBNKCMHBYb5KPNf7hmP7B7giLJgM15HNT3hUzE9jzpS8CNOfZl0gDphZ2iNz73uUdq7mbT9nID5P9 Ogq93pfIeaV/s9B0+vywfYZAaDwUB3hnGGuq6tVb0R7l/rDlBzOtqsVd7ySWqeo508C9VaNdGq8oo 4W8waHnUThRogvZinl+yI/ChY9U2/QgiQ5YCn5IDsk2QkHLSXskcm5zKtIdIvqmcpaaqpTAeAG5nO 0Pd4k1vA==; In-Reply-To: <87sfwaav0l.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 06 Nov 2021 03:16:26 +0100") X-AuthUser: masked@neverwas.me X-Zone-Spam-Resolution: no action X-Zone-Spam-Status: No, score=-0.1, required=15, tests=[ARC_NA=0, FROM_HAS_DN=0, RCPT_COUNT_THREE=0, TO_DN_SOME=0, HAS_ATTACHMENT=0, FROM_EQ_ENVFROM=0, MIME_TRACE=0, MIME_GOOD=-0.1, NEURAL_SPAM=0, MID_RHS_MATCH_FROM=0, RCVD_COUNT_ZERO=0] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:219086 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > "J.P." writes: > >> Subject: [PATCH] Normalize usage of variable erc-server-reconnecting > > I think I managed to follow the logic of this change, and it doesn't > seem to regress anything after a bit of testing, so I've pushed it to > Emacs 29. Thanks Lars. As you may recall, I'm quite slow, often in more ways than one. And that certainly applies here. Turns out I've been sitting on slightly revised versions of both this and bug#50008: 28.0.50; ERC sends empty lines with user input which you also recently added. For some reason (not sloth/dimwittedness, I assure you), I only updated the versions of these patches living in #48598 but neglected to follow suit with these two threads. So with much contrition, I've isolated the differences and attached them here. The updates to this bug attempt to preserve a couple API elements I ditched/clobbered in what's already been installed (in the unlikely event some poor sap or bot actually depended on them). This is mainly an effort to embrace the spirit of being more responsible with and accountable for my changes, something I've been slow to pick up on from the great bandali. That said, I totally understand if you'd rather I learn to live with my mistakes as well. The minor changes to the other, "empty lines" patch just involve another instance of superfluous newlines, this time generated from the function `erc-cmd-default'. Thanks again and sorry for the disturbance. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Deprecate-instead-of-redefine-erc-server-reconnectin.patch >From 9a230327870370ca2d3861c6a891d83e3e8ed0d0 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 11 Jun 2021 03:55:07 -0700 Subject: [PATCH 1/2] Deprecate instead of redefine erc-server-reconnecting * lisp/erc/erc-backend.el (erc-server-reconnecting, erc--server-reconnecting): obsolete and replace the former with new internal variant, which carries a simplified meaning. (erc-server-reconnect-p, erc--server-reconnect-p): Obsolete and replace the former with an internal function, and change behavior to disregard `erc-server-reconnecting' when rendering verdict. (erc-process-sentinel-2): ensure local var `erc--server-reconnecting' is t when timers are scheduled or firing, and nil otherwise, including after retries exhausted. This agrees with the straightforward way `erc-server-reconnecting' has always been used by `erc-cmd-RECONNECT'. (erc-server-connect): set `erc--server-reconnecting'. * lisp/erc/erc.el (erc-cmd-RECONNECT): use `erc--server-reconnecting' instead of `erc-server-reconnecting'. --- lisp/erc/erc-backend.el | 26 +++++++++++++++++++++----- lisp/erc/erc.el | 8 ++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 6e5a768b70..69f63dfbc4 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -197,7 +197,13 @@ erc-server-quitting "Non-nil if the user requests a quit.") (defvar-local erc-server-reconnecting nil - "Non-nil if reconnecting or scheduled to.") + "Non-nil if the user requests an explicit reconnect, and the +current IRC process is still alive.") +(make-obsolete-variable 'erc-server-reconnecting + "see `erc--server-reconnecting'" "29.1") + +(defvar-local erc--server-reconnecting nil + "Non-nil when reconnecting.") (defvar-local erc-server-timed-out nil "Non-nil if the IRC server failed to respond to a ping.") @@ -532,7 +538,8 @@ erc-server-connect (with-current-buffer buffer (setq erc-server-process process) (setq erc-server-quitting nil) - (setq erc-server-reconnecting nil) + (setq erc-server-reconnecting nil + erc--server-reconnecting nil) (setq erc-server-timed-out nil) (setq erc-server-banned nil) (setq erc-server-error-occurred nil) @@ -616,7 +623,7 @@ erc-server-filter-function (erc-parse-server-response process line))))))) (defun erc--server-reconnect-p (event) - "Return non-nil if ERC should attempt to reconnect automatically. + "Return non-nil when ERC should attempt to reconnect. EVENT is the message received from the closed connection process." (and erc-server-auto-reconnect (not erc-server-banned) @@ -631,6 +638,14 @@ erc--server-reconnect-p ;; open-network-stream-nowait error for connection refused (if (string-match "^failed with code 111" event) 'nonblocking t))) +(defun erc-server-reconnect-p (event) + "Return non-nil if ERC should attempt to reconnect automatically. +EVENT is the message received from the closed connection process." + (declare (obsolete "see `erc--server-reconnect-p'" "29.1")) + (or (with-suppressed-warnings ((obsolete erc-server-reconnecting)) + erc-server-reconnecting) + (erc--server-reconnect-p event))) + (defun erc-process-sentinel-2 (event buffer) "Called when `erc-process-sentinel-1' has detected an unexpected disconnect." (if (not (buffer-live-p buffer)) @@ -642,7 +657,7 @@ erc-process-sentinel-2 (if (not reconnect-p) ;; terminate, do not reconnect (progn - (setq erc-server-reconnecting nil) + (setq erc--server-reconnecting nil) (erc-display-message nil 'error (current-buffer) 'terminated ?e event) ;; Update mode line indicators @@ -651,7 +666,8 @@ erc-process-sentinel-2 ;; reconnect (condition-case nil (progn - (setq erc-server-reconnecting t + (setq erc-server-reconnecting nil + erc--server-reconnecting t erc-server-reconnect-count (1+ erc-server-reconnect-count)) (setq delay erc-server-reconnect-timeout) (run-at-time delay nil diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 0da837012c..9fa1736535 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -3752,13 +3752,17 @@ erc-cmd-RECONNECT (setq buffer (current-buffer))) (with-current-buffer buffer (setq erc-server-quitting nil) - (setq erc-server-reconnecting t) + (with-suppressed-warnings ((obsolete erc-server-reconnecting)) + (setq erc-server-reconnecting t)) + (setq erc--server-reconnecting t) (setq erc-server-reconnect-count 0) (setq process (get-buffer-process (erc-server-buffer))) (if process (delete-process process) (erc-server-reconnect)) - (setq erc-server-reconnecting nil))) + (with-suppressed-warnings ((obsolete erc-server-reconnecting)) + (setq erc-server-reconnecting nil)) + (setq erc--server-reconnecting nil))) t) (put 'erc-cmd-RECONNECT 'process-not-needed t) -- 2.31.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Don-t-send-empty-lines-for-unknown-commands-in-ERC.patch >From a2d249d758f49ba528243204e32ecd0aa59c3105 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 13 Jun 2021 02:15:55 -0700 Subject: [PATCH 2/2] Don't send empty lines for unknown commands in ERC * lisp/erc/erc.el (erc-cmd-default): prevent excess trailing newlines from being sent. * test/lisp/erc/erc-tests.el: Update `erc-process-input-line' test to check for excess line feeds with unknown commands. --- lisp/erc/erc.el | 2 +- test/lisp/erc/erc-tests.el | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 9fa1736535..8e2bb83360 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2965,7 +2965,7 @@ erc-cmd-default this function. LINE is sent to the server verbatim, and therefore has to contain the command itself as well." (erc-log (format "cmd: DEFAULT: %s" line)) - (erc-server-send (substring line 1)) + (erc-server-send (string-trim-right (substring line 1) "[\r\n]")) t) (defvar erc--read-time-period-history nil) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 685f4e2bea..b2dbc1012d 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -236,6 +236,7 @@ erc-process-input-line (let (erc-server-last-sent-time erc-server-flood-queue (orig-erc-cmd-MSG (symbol-function 'erc-cmd-MSG)) + (erc-default-recipients '("#chan")) calls) (with-temp-buffer (cl-letf (((symbol-function 'erc-cmd-MSG) @@ -247,9 +248,7 @@ erc-process-input-line ((symbol-function 'erc-server-process-alive) (lambda () t)) ((symbol-function 'erc-server-send-queue) - #'ignore) - ((symbol-function 'erc-default-target) - (lambda () "" "#chan"))) + #'ignore)) (ert-info ("Dispatch to user command handler") @@ -259,6 +258,16 @@ erc-process-input-line (should (equal (pop erc-server-flood-queue) '("PRIVMSG #chan :hi\r\n" . utf-8)))) + (ert-info ("Quote preserves line intact") + (erc-process-input-line "/QUOTE FAKE foo bar\n") + (should (equal (pop erc-server-flood-queue) + '("FAKE foo bar\r\n" . utf-8)))) + + (ert-info ("Unknown command respected") + (erc-process-input-line "/FAKE foo bar\n") + (should (equal (pop erc-server-flood-queue) + '("FAKE foo bar\r\n" . utf-8)))) + (ert-info ("Spaces preserved") (erc-process-input-line "/msg #chan hi you\n") (should (equal (pop calls) " #chan hi you")) -- 2.31.1 --=-=-=--