all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tomas Volf <~@wolfsden.cz>
To: 74284@debbugs.gnu.org
Subject: bug#74284: Shepherd does not respect ordering for one-shot? services
Date: Sat, 09 Nov 2024 17:53:18 +0100	[thread overview]
Message-ID: <87ses073i9.fsf@wolfsden.cz> (raw)


Hello,

I think I found a bug in the GNU Shepherd.  Dependencies between
one-shot? #t services do not seem to be respected.

Documentation for #:requirement says the following (emphasis mine):

--8<---------------cut here---------------start------------->8---
#:requirement is, like provision, a list of symbols that specify
services. In this case, they name what this service depends on: before
the service can be started, services that provide those symbols *must be
started*.

Note that every name listed in #:requirement must be registered so it
can be resolved (see Service Registry).
--8<---------------cut here---------------end--------------->8---

Documentation for #:one-shot? says the following:

--8<---------------cut here---------------start------------->8---
Whether the service is a one-shot service. A one-shot service is a
service that, as soon as it has been successfully started, is marked as
“stopped.” Other services can nonetheless require one-shot
services. One-shot services are useful to trigger an action before other
services are started, such as a cleanup or an initialization action.

As for other services, the start method of a one-shot service must
return a truth value to indicate success, and false to indicate failure.
--8<---------------cut here---------------end--------------->8---

Nothing in there seems to mention that one-shot? services do not
actually wait on each other.  To reproduce I wrote a simple
configuration file:

--8<---------------cut here---------------start------------->8---
(define %one-shot #f)

(use-modules (srfi srfi-1))

(define (make-waiting-service name wait requirement)
  (service (list name)
           #:requirement requirement
           #:start (λ _
                     (sleep wait)
                     (format #t "~a\n" name)
                     #t)
           #:one-shot? %one-shot))

(let ((svcs (pair-fold (λ (names waits svcs)
                         (cons (make-waiting-service (car names)
                                                     (car waits)
                                                     (cdr names))
                               svcs))
                       '()
                       '(a b c d)
                       '(1 2 3 4))))
  (register-services svcs)
  (start-in-the-background (map service-canonical-name svcs)))
--8<---------------cut here---------------end--------------->8---

Each service sleeps for `wait' seconds to simulate some slow work being
done.  In effect that means that each of the services takes different
time to start up.

Now, when we run it as it is, we get the following (correct) output:

--8<---------------cut here---------------start------------->8---
$ shepherd -c conf.scm
Starting service root...
Service root started.
Service root running with value #t.
Service root has been started.
Configuration successfully loaded from 'conf.scm'.
Starting service d...
d
Service d has been started.
Service d started.
Service d running with value #t.
Starting service c...
c
Service c has been started.
Service c started.
Service c running with value #t.
Starting service b...
b
Service b has been started.
Service b started.
Service b running with value #t.
Starting service a...
a
Service a has been started.
Service a started.
Successfully started 4 services in the background.
Service a running with value #t.
--8<---------------cut here---------------end--------------->8---

Notice the start-up order (d c b a).  If you run it, you will also
notice that `d' takes 4 seconds to start up, `c' 3 seconds etc.

However if we change the define at the top of the configuration file to
#t, hence:

--8<---------------cut here---------------start------------->8---
(define %one-shot #t)
--8<---------------cut here---------------end--------------->8---

The behavior changes:

--8<---------------cut here---------------start------------->8---
$ shepherd -c conf.scm
Starting service root...
Service root started.
Service root running with value #t.
Service root has been started.
Configuration successfully loaded from 'conf.scm'.
Starting service d...
Starting service c...
Starting service b...
Starting service a...
a
Service a has been started.
Service a started.
Service a running with value #t.
b
Service b has been started.
Service b started.
Service b running with value #t.
c
Service c has been started.
Service c started.
Service c running with value #t.
d
Service d has been started.
Service d started.
Successfully started 4 services in the background.
Service d running with value #t.
--8<---------------cut here---------------end--------------->8---

Notice that the order changed to (a b c d, this matches the increasing
wait time), the initial messages are all together:

--8<---------------cut here---------------start------------->8---
Starting service d...
Starting service c...
Starting service b...
Starting service a...
--8<---------------cut here---------------end--------------->8---

and the whole start-up takes 4 seconds (the wait time of `d').  That
seems to indicate that all 4 services are actually starting at the same
time without waiting as they should per the #:requirement argument.



Have a nice day,
Tomas

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.




             reply	other threads:[~2024-11-09 16:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-09 16:53 Tomas Volf [this message]
2024-11-22 14:37 ` bug#74284: Shepherd does not respect ordering for one-shot? services Ludovic Courtès
2024-11-22 19:41   ` Tomas Volf

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=87ses073i9.fsf@wolfsden.cz \
    --to=~@wolfsden.cz \
    --cc=74284@debbugs.gnu.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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.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.