supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
From: Adam Joseph <adam@westernsemico.com>
To: supervision@list.skarnet.org
Subject: s6-rc-update does not create pipes when already-running service becomes a consumer
Date: Tue, 26 Sep 2023 07:33:28 -0700	[thread overview]
Message-ID: <169573880839.4539.10047970009995756240@localhost> (raw)

A simple script to demonstrate this problem is attached below.

It appears that s6-rc-update will neglect to create the needed pipes in the
following situation:

1. A service X is already running before s6-rc-update is invoked
2. Service X was not the consumer-for any other service prior to s6-rc-update
3. Service X is the consumer-for at least one service after s6-rc-update

A similar problem occurs with producer-for.

The fix is relatively straightforward; in fill_convtable_and_flags() a check is
needed to detect if olddb->services[i].x.longrun.nproducers==0 is different from
newdb->services[x].x.longrun.nproducers==0; if so, the
NEWSTATE_IS_BIJECTIVE_CONVERSION_TARGET flag should not be added to newstate[x]
and instead OLDSTATE_RESTART should be added to oldstate[i].  I have a patch
that implements this, and the corresponding check for longrun.consumer.

Below is a crude shell script which demonstrates the bug.  It does not require
root.  Before running the script below, you must run the following command on a
different terminal (you'll want to observe its output):

mkdir -p /tmp/live/service
s6-svscan -- /tmp/live/service/

Here is the script:

#!/bin/bash
mkdir -p source/consumer
echo longrun > source/consumer/type
echo -e '#!/bin/bash\ncat > /dev/null' > source/consumer/run
chmod +x source/consumer/run

mkdir source/producer
echo longrun > source/producer/type
echo -e '#!/bin/bash\nwhile true; do sleep 1; date; done\n' > source/producer/run
chmod +x source/producer/run

s6-rc-compile compiled source
s6-rc-init -l /tmp/live/compiled -c $(pwd)/compiled /tmp/live/service/
s6-rc -l /tmp/live/compiled start producer consumer s6rc-fdholder

echo <<EOF
at this point you will see the output of "producer" in the terminal
window where s6-svscan is running -- its output goes to the catch-all logger

next, we will add the producer/consumer funnel links.  however since the
services have already started, they will not be *re*started, and s6-fdholder
wont have the necessary file descriptors
EOF
sleep 5

echo producer > source/consumer/consumer-for
echo consumer > source/producer/producer-for
s6-rc-compile compiled2 source
s6-rc-update -l /tmp/live/compiled $(pwd)/compiled2

echo <<EOF
next we restart the producer (only); you should see messages like the following
on the catch-all logger:
  s6-fdholder-retrieve: fatal: unable to retrieve fd for id pipe:s6rc-w-consumer: No such file or directory
EOF
sleep 5
s6-rc -l /tmp/live/compiled stop producer
s6-rc -l /tmp/live/compiled start producer

             reply	other threads:[~2023-09-26 14:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-26 14:33 Adam Joseph [this message]
2023-09-26 19:23 ` Laurent Bercot
2023-09-27 16:09   ` Samuel Holland

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=169573880839.4539.10047970009995756240@localhost \
    --to=adam@westernsemico.com \
    --cc=supervision@list.skarnet.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).