From: Katsumi Yamaoka <yamaoka@jpl.org>
To: ding@gnus.org
Subject: Re: closing all inactive server connections
Date: Tue, 31 Jul 2007 17:52:42 +0900 [thread overview]
Message-ID: <b4modhtrm3o.fsf@jpl.org> (raw)
In-Reply-To: <m26441l0p6.fsf@lifelogs.com>
[-- Attachment #1: Type: text/plain, Size: 503 bytes --]
>>>>> Ted Zlatanov wrote:
KY> --- nntp.el~ 2007-07-18 12:07:39 +0000
KY> +++ nntp.el 2007-07-31 03:04:52 +0000
> I tried it and the IMAP server still hangs. Maybe the fix is in
> nnimap.el? I haven't looked deeper into this issue but I'll be glad to
> debug things on my side.
Is the patch effective for the hanged nntp connections?
Well, I tried looking into the IMAP code although I've never
used nnimap. And I found the functions that communicate with
the server all have the following form:
[-- Attachment #2: Type: application/emacs-lisp, Size: 166 bytes --]
[-- Attachment #3: Type: text/plain, Size: 528 bytes --]
This can be an infinite loop if the process-status keeps `open'
or `run' even though the connection has actually died. In
particular, the `imap-wait-for-tag' function can be the cause of
the hanging since it sends the LOGOUT command to the dead server
and waits for the response. So, I tried modifying it so as to
quit in a certain time. The patch to imap.el is below. Anyway,
it needs to be reviewed by someone who is skilled in IMAP. The
default value of `imap-timeout-seconds' might be too small for
slow connections.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: Type: text/x-patch, Size: 3163 bytes --]
--- imap.el~ 2007-01-24 07:15:37 +0000
+++ imap.el 2007-07-31 08:50:30 +0000
@@ -1182,14 +1182,25 @@
imap-server auth)))))
imap-state))))
+(defvar imap-timeout-seconds 1
+ "*Number of seconds in which `imap-close' gives up working.")
+
+(defvar imap-timeout nil
+ "Flag that indicates process should die immediately.")
+
(defun imap-close (&optional buffer)
"Close connection to server in BUFFER.
If BUFFER is nil, the current buffer is used."
(with-current-buffer (or buffer (current-buffer))
(when (imap-opened)
- (condition-case nil
- (imap-send-command-wait "LOGOUT")
- (quit nil)))
+ (let ((timer (run-at-time imap-timeout-seconds nil
+ #'set 'imap-timeout t)))
+ (unwind-protect
+ (condition-case nil
+ (imap-send-command-wait "LOGOUT")
+ (quit nil)))
+ (cancel-timer timer)
+ (setq imap-timeout nil)))
(when (and imap-process
(memq (process-status imap-process) '(open run)))
(delete-process imap-process))
@@ -1882,30 +1893,35 @@
(while (and (null imap-continuation)
(memq (process-status imap-process) '(open run))
(< imap-reached-tag tag))
- (let ((len (/ (point-max) 1024))
- message-log-max)
- (unless (< len 10)
- (setq imap-have-messaged t)
- (message "imap read: %dk" len))
- (accept-process-output imap-process
- (truncate imap-read-timeout)
- (truncate (* (- imap-read-timeout
- (truncate imap-read-timeout))
- 1000)))))
- ;; A process can die _before_ we have processed everything it
- ;; has to say. Moreover, this can happen in between the call to
- ;; accept-process-output and the call to process-status in an
- ;; iteration of the loop above.
- (when (and (null imap-continuation)
- (< imap-reached-tag tag))
- (accept-process-output imap-process 0 0))
- (when imap-have-messaged
- (message ""))
- (and (memq (process-status imap-process) '(open run))
- (or (assq tag imap-failed-tags)
- (if imap-continuation
- 'INCOMPLETE
- 'OK))))))
+ (if imap-timeout
+ (progn
+ (setq imap-timeout nil)
+ (delete-process imap-process))
+ (let ((len (/ (point-max) 1024))
+ message-log-max)
+ (unless (< len 10)
+ (setq imap-have-messaged t)
+ (message "imap read: %dk" len))
+ (accept-process-output imap-process
+ (truncate imap-read-timeout)
+ (truncate (* (- imap-read-timeout
+ (truncate imap-read-timeout))
+ 1000))))))
+ (when (memq (process-status imap-process) '(open run))
+ ;; A process can die _before_ we have processed everything it
+ ;; has to say. Moreover, this can happen in between the call to
+ ;; accept-process-output and the call to process-status in an
+ ;; iteration of the loop above.
+ (when (and (null imap-continuation)
+ (< imap-reached-tag tag))
+ (accept-process-output imap-process 0 0))
+ (when imap-have-messaged
+ (message ""))
+ (and (memq (process-status imap-process) '(open run))
+ (or (assq tag imap-failed-tags)
+ (if imap-continuation
+ 'INCOMPLETE
+ 'OK)))))))
(defun imap-sentinel (process string)
(delete-process process))
next prev parent reply other threads:[~2007-07-31 8:52 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-07 15:59 Ted Zlatanov
2007-07-10 19:54 ` Ted Zlatanov
2007-07-19 13:46 ` Ted Zlatanov
2007-07-27 17:06 ` Ted Zlatanov
2007-07-28 0:18 ` Ted Zlatanov
2007-07-30 6:22 ` Katsumi Yamaoka
2007-07-30 15:39 ` Ted Zlatanov
2007-07-31 2:57 ` Katsumi Yamaoka
2007-07-31 3:08 ` Katsumi Yamaoka
2007-07-31 3:19 ` Ted Zlatanov
2007-07-31 8:52 ` Katsumi Yamaoka [this message]
2007-08-02 19:51 ` Ted Zlatanov
2007-08-15 11:28 ` Simon Josefsson
2007-08-16 7:18 ` Katsumi Yamaoka
2007-08-16 7:25 ` Katsumi Yamaoka
2007-08-16 9:49 ` Simon Josefsson
2007-08-16 15:35 ` Ted Zlatanov
2007-08-16 15:32 ` Ted Zlatanov
2007-08-16 15:56 ` Ted Zlatanov
2007-08-16 23:19 ` Katsumi Yamaoka
2007-08-16 23:25 ` Ted Zlatanov
2007-08-16 23:47 ` Katsumi Yamaoka
2007-08-17 11:09 ` Katsumi Yamaoka
2007-09-10 14:52 ` Ted Zlatanov
2007-08-15 18:28 ` Reiner Steib
2007-07-31 3:16 ` Ted Zlatanov
2007-07-31 3:19 ` Katsumi Yamaoka
2007-07-31 2:58 ` untabify Lisp sources (was Re: closing all inactive server connections) Katsumi Yamaoka
2007-07-31 22:05 ` untabify Lisp sources Reiner Steib
2007-08-01 2:44 ` Ted Zlatanov
2007-07-31 22:57 ` Miles Bader
2007-08-01 2:46 ` Ted Zlatanov
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=b4modhtrm3o.fsf@jpl.org \
--to=yamaoka@jpl.org \
--cc=ding@gnus.org \
/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.
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 NNTP newsgroup(s).