From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/65004 Path: news.gmane.org!not-for-mail From: Katsumi Yamaoka Newsgroups: gmane.emacs.gnus.general Subject: Re: closing all inactive server connections Date: Tue, 31 Jul 2007 17:52:42 +0900 Organization: Emacsen advocacy group Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1185872024 20551 80.91.229.12 (31 Jul 2007 08:53:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 31 Jul 2007 08:53:44 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M13514=ding+2Daccount=gmane.org@lists.math.uh.edu Tue Jul 31 10:53:37 2007 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.50) id 1IFnU1-0000Pi-8x for ding-account@gmane.org; Tue, 31 Jul 2007 10:53:37 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1IFnU0-0001VY-3m for ding-account@gmane.org; Tue, 31 Jul 2007 03:53:36 -0500 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1IFnTx-0001VQ-9R for ding@lists.math.uh.edu; Tue, 31 Jul 2007 03:53:33 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtp (Exim 4.67) (envelope-from ) id 1IFnTq-0000Yj-QQ for ding@lists.math.uh.edu; Tue, 31 Jul 2007 03:53:33 -0500 Original-Received: from orlando.hostforweb.net ([216.246.45.90]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1IFnTp-00038x-00 for ; Tue, 31 Jul 2007 10:53:25 +0200 Original-Received: from [66.225.201.151] (port=33844 helo=mail.jpl.org) by orlando.hostforweb.net with esmtpa (Exim 4.63) (envelope-from ) id 1IFnTD-0006xx-Eg for ding@gnus.org; Tue, 31 Jul 2007 03:52:47 -0500 X-Hashcash: 1:20:070731:ding@gnus.org::NqOdAidx3R92cSkd:00006f/d X-Face: #kKnN,xUnmKia.'[pp`;Omh}odZK)?7wQSl"4o04=EixTF+V[""w~iNbM9ZL+.b*_CxUmFk B#Fu[*?MZZH@IkN:!"\w%I_zt>[$nm7nQosZ<3eu;B:$Q_:p!',P.c0-_Cy[dz4oIpw0ESA^D*1Lw= L&i*6&( User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:2eHS7GwAUP+uAwIFIv4yBPHCU1g= X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - orlando.hostforweb.net X-AntiAbuse: Original Domain - gnus.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - jpl.org X-Source: X-Source-Args: X-Source-Dir: X-Spam-Score: -2.4 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:65004 Archived-At: --=-=-= >>>>> 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: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline (while (and (memq (process-status PROCESS) '(open run)) (wait-for-a-string-that-the-PROCESS-returns)) (accept-process-output PROCESS 1) (sit-for 1)) --=-=-= Content-Disposition: inline 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline --- 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)) --=-=-=--