all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "J.P." <jp@neverwas.me>
To: xoddf2 <woddfellow2@gmail.com>
Cc: emacs-erc@gnu.org, 62044@debbugs.gnu.org
Subject: bug#62044: 30.0.50; ERC 5.5: Auto-reconnect is broken
Date: Wed, 08 Mar 2023 18:22:47 -0800	[thread overview]
Message-ID: <87fsaepsso.fsf__10710.6313620292$1678328668$gmane$org@neverwas.me> (raw)
In-Reply-To: <878rg7ql29.fsf@neverwas.me> (J. P.'s message of "Wed, 08 Mar 2023 08:12:14 -0800")

[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]

"J.P." <jp@neverwas.me> writes:

> In your initial report, underlying connectivity is present in some
> form because ERC reaches the "Logging in as" stage and attempts to
> send an application payload,

Actually, this is nonsense (forgive me). I seem to have forgotten that
ERC prints this message regardless of whether a connection attempt
succeeds.

> So to keep things sane, we should probably treat auto-reconnecting
> across connectivity gaps as a wishlist item and auto-reconnecting atop
> healthy connections as an existing, previously unreported bug. As for
> the new feature, I've attached a POC patch that you can try if you're
> willing (usage is self-explanatory, but feel free to modify or iterate
> as needed).

I've attached a less sloppy version that probably still fails in some
common cases, but at least it reuses the existing session connector.

> As for the other issue, I think we're going to need some genuine
> session logs to really get anywhere. That is, we'll likely need you to
> enable logging and tracing during a real session with your bouncer
> over a hopefully not-too-prolonged period to capture an actual
> reconnect sequence failing. But hold off on that for another round
> unless you're feeling adventurous.

Actually, I'm not sure we'll be needing these logs after all. Let's
maybe think on it a bit more (if that's acceptable). Thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0000-v1-v2.diff --]
[-- Type: text/x-patch, Size: 3886 bytes --]

From 01a2aa830b73028aecf1f7dae7dadba7467a3144 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Wed, 8 Mar 2023 18:04:16 -0800
Subject: [PATCH 0/1] *** NOT A PATCH ***

*** BLURB HERE ***

F. Jason Park (1):
  Add conditional erc-server-reconnect-function

 lisp/erc/erc-backend.el | 56 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

Interdiff:
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index d1738e4f92d..d289df98bab 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -749,6 +749,9 @@ erc--server-reconnect-timeout
 (defun erc-server-delayed-check-reconnect (buffer)
   "Wait for internet connectivity before trying to reconnect.
 BUFFER is the server buffer for the current connection."
+  ;; This may appear to hang for a good while at various places
+  ;; because it calls wait_reading_process_output a bunch.  It does at
+  ;; least sometimes print "Waiting for socket from ..." or similar.
   (with-current-buffer buffer
     (setq erc--server-reconnect-timeout
           (min 300 (* (or erc--server-reconnect-timeout
@@ -763,26 +766,38 @@ erc-server-delayed-check-reconnect
                  (erc-display-message nil 'error buffer "Nobody home...")
                  (erc-schedule-reconnect buffer 0))))))
       (condition-case _
-          (make-network-process
-           :name "*erc-connectivity-check"
-           :host erc-session-server
-           :service erc-session-port
-           :nowait t
-           :filter
-           (lambda (proc _)
-             (delete-process proc)
-             (with-current-buffer buffer
-               (setq erc--server-reconnect-timeout nil))
-             (run-at-time nil nil #'erc-server-delayed-reconnect buffer))
-           :sentinel
-           (lambda (cproc event)
-             (with-current-buffer buffer
-               (pcase event
-                 ("open\n"
-                  (run-at-time nil nil #'send-string
-                               cproc "PING *connect-check*\r\n"))
-                 ("connection broken by remote peer\n"
-                  (funcall reschedule cproc))))))
+          (let ((proc (funcall erc-session-connector
+                               "*erc-connectivity-check" nil
+                               erc-session-server erc-session-port
+                               :nowait t))
+                tls-check)
+            (when (and (not (eq erc-session-connector
+                                #'erc-open-network-stream))
+                       (process-contact proc :tls-parameters))
+              (setq tls-check
+                    (run-at-time
+                     1 1 (lambda (proc)
+                           (unless (eq 'connect (process-status proc))
+                             (cancel-timer tls-check))
+                           (when (eq 'failed (process-status proc))
+                             (funcall reschedule proc)))
+                     proc)))
+            (set-process-filter
+             proc (lambda (proc _)
+                    (delete-process proc)
+                    (with-current-buffer buffer
+                      (setq erc--server-reconnect-timeout nil))
+                    (run-at-time nil nil #'erc-server-delayed-reconnect
+                                 buffer)))
+            (set-process-sentinel
+             proc (lambda (cproc event)
+                    (with-current-buffer buffer
+                      (pcase event
+                        ("open\n"
+                         (run-at-time nil nil #'send-string
+                                      cproc "PING *connect-check*\r\n"))
+                        ("connection broken by remote peer\n"
+                         (funcall reschedule cproc)))))))
         (file-error (funcall reschedule nil))))))
 
 (defun erc-server-filter-function (process string)
-- 
2.39.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-Add-conditional-erc-server-reconnect-function.patch --]
[-- Type: text/x-patch, Size: 3738 bytes --]

From 01a2aa830b73028aecf1f7dae7dadba7467a3144 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Wed, 8 Mar 2023 06:14:36 -0800
Subject: [PATCH 1/1] Add conditional erc-server-reconnect-function

* lisp/erc/erc-backend.el (erc--server-reconnect-timer,
erc-server-delayed-check-reconnect): Add possible alternate value for
option `erc-server-reconnect-function' that only attempts to reconnect
after hearing back from the server.  Also add helper variable.
---
 lisp/erc/erc-backend.el | 56 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 567443f5329..d289df98bab 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -744,6 +744,62 @@ erc-server-delayed-reconnect
     (with-current-buffer buffer
       (erc-server-reconnect))))
 
+(defvar-local erc--server-reconnect-timeout nil)
+
+(defun erc-server-delayed-check-reconnect (buffer)
+  "Wait for internet connectivity before trying to reconnect.
+BUFFER is the server buffer for the current connection."
+  ;; This may appear to hang for a good while at various places
+  ;; because it calls wait_reading_process_output a bunch.  It does at
+  ;; least sometimes print "Waiting for socket from ..." or similar.
+  (with-current-buffer buffer
+    (setq erc--server-reconnect-timeout
+          (min 300 (* (or erc--server-reconnect-timeout
+                          erc-server-reconnect-timeout)
+                      2)))
+    (let ((reschedule
+           (lambda (proc)
+             (let ((erc-server-reconnect-timeout
+                    erc--server-reconnect-timeout))
+               (with-current-buffer buffer
+                 (delete-process proc)
+                 (erc-display-message nil 'error buffer "Nobody home...")
+                 (erc-schedule-reconnect buffer 0))))))
+      (condition-case _
+          (let ((proc (funcall erc-session-connector
+                               "*erc-connectivity-check" nil
+                               erc-session-server erc-session-port
+                               :nowait t))
+                tls-check)
+            (when (and (not (eq erc-session-connector
+                                #'erc-open-network-stream))
+                       (process-contact proc :tls-parameters))
+              (setq tls-check
+                    (run-at-time
+                     1 1 (lambda (proc)
+                           (unless (eq 'connect (process-status proc))
+                             (cancel-timer tls-check))
+                           (when (eq 'failed (process-status proc))
+                             (funcall reschedule proc)))
+                     proc)))
+            (set-process-filter
+             proc (lambda (proc _)
+                    (delete-process proc)
+                    (with-current-buffer buffer
+                      (setq erc--server-reconnect-timeout nil))
+                    (run-at-time nil nil #'erc-server-delayed-reconnect
+                                 buffer)))
+            (set-process-sentinel
+             proc (lambda (cproc event)
+                    (with-current-buffer buffer
+                      (pcase event
+                        ("open\n"
+                         (run-at-time nil nil #'send-string
+                                      cproc "PING *connect-check*\r\n"))
+                        ("connection broken by remote peer\n"
+                         (funcall reschedule cproc)))))))
+        (file-error (funcall reschedule nil))))))
+
 (defun erc-server-filter-function (process string)
   "The process filter for the ERC server."
   (with-current-buffer (process-buffer process)
-- 
2.39.2


  parent reply	other threads:[~2023-03-09  2:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08  6:12 bug#62044: 30.0.50; ERC 5.5: Auto-reconnect is broken xoddf2
2023-03-08  7:56 ` J.P.
     [not found] ` <87pm9jy8v7.fsf@neverwas.me>
2023-03-08  9:07   ` xoddf2
     [not found]   ` <87sfefr4qa.fsf@gmail.com>
2023-03-08 16:12     ` J.P.
     [not found]     ` <878rg7ql29.fsf@neverwas.me>
2023-03-09  2:22       ` J.P. [this message]
     [not found]       ` <87fsaepsso.fsf@neverwas.me>
2023-03-09 14:38         ` J.P.
     [not found]         ` <87lek6kn1b.fsf@neverwas.me>
2023-03-10  7:34           ` xoddf2
     [not found]           ` <87zg8lawlk.fsf@gmail.com>
2023-03-11 18:52             ` J.P.
     [not found]             ` <87v8j715om.fsf@neverwas.me>
2023-04-10 20:25               ` J.P.
2024-04-29  9:56 ` bug#62044: Status update? Alexis
2024-05-03  2:32   ` bug#62044: 30.0.50; ERC 5.5: Auto-reconnect is broken J.P.
     [not found]   ` <87wmoby69b.fsf@neverwas.me>
2024-05-09  6:13     ` Alexis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='87fsaepsso.fsf__10710.6313620292$1678328668$gmane$org@neverwas.me' \
    --to=jp@neverwas.me \
    --cc=62044@debbugs.gnu.org \
    --cc=emacs-erc@gnu.org \
    --cc=woddfellow2@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.