guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/04: processes: Gracefully handle daemons without clients.


From: guix-commits
Subject: 02/04: processes: Gracefully handle daemons without clients.
Date: Mon, 29 Apr 2019 16:25:35 -0400 (EDT)

civodul pushed a commit to branch version-1.0.0
in repository guix.

commit c20d4cac1fb72afe26a3e534b92e9a9691936458
Author: Ludovic Courtès <address@hidden>
Date:   Mon Apr 29 21:42:04 2019 +0200

    processes: Gracefully handle daemons without clients.
    
    Fixes <https://bugs.gnu.org/34716>.
    Reported by Mark H Weaver <address@hidden>.
    
    The problem could be reproduced by running, on one hand:
    
      sh -c 'exec -a guix-daemon sleep 777'
    
    and on the other hand:
    
      guix processes
    
    If there is no process with PID 777, 'guix processes' would barf as it
    stumbles upon a <daemon-session> record whose client is #f.
    
    * guix/scripts/processes.scm (daemon-sessions)[child-process->session]:
    New procedure, with lambda formerly passed to 'map'.  Handle #f returns
    from 'lookup-process'.
    Call 'child-process->session' within 'filter-map', not just 'map'.
---
 guix/scripts/processes.scm | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/guix/scripts/processes.scm b/guix/scripts/processes.scm
index 2dd3bbf..a2ab017 100644
--- a/guix/scripts/processes.scm
+++ b/guix/scripts/processes.scm
@@ -158,15 +158,22 @@ active sessions, and the master 'guix-daemon' process."
                      (= pid (process-parent-id process))))
               processes))
 
-    (values (map (lambda (process)
-                   (match (process-command process)
-                     ((argv0 (= string->number client) _ ...)
-                      (let ((files (process-open-files process)))
-                        (daemon-session process
-                                        (lookup-process client)
-                                        (lookup-children (process-id process))
-                                        (filter lock-file? files))))))
-                 children)
+    (define (child-process->session process)
+      (match (process-command process)
+        ((argv0 (= string->number client) _ ...)
+         (let ((files  (process-open-files process))
+               (client (lookup-process client)))
+           ;; After a client has died, there's a window during which its
+           ;; corresponding 'guix-daemon' process is still alive, in which
+           ;; case 'lookup-process' returns #f.  In that case ignore the
+           ;; session.
+           (and client
+                (daemon-session process client
+                                (lookup-children
+                                 (process-id process))
+                                (filter lock-file? files)))))))
+
+    (values (filter-map child-process->session children)
             master)))
 
 (define (daemon-session->recutils session port)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]