debian-forge/osbuild
David Rheinsberg 803433fb62 api: prevent early output retrieval
Change the API endpoint to prevent retrieving monitor-output from a
running instance. Instead, we require the caller to exit the API context
before querying the monitor-output. This guarantees that the api-thread
was synchronously taken down and scheduled any outstanding events.

This fixes an issue where a side-channel notifies us of a buildroot
exit, but the api-thread has not yet returned from epoll, and thus might
not have dispatched pending I/O events, yet. If we instead wait for the
thread to exit, we have a synchronous shutdown and know that all
*ordered* kernel events must have been handled.

In particular, imagine a build-root program running (like `echo` in the
test_monitor unittest) which writes data to the stdout-pipe and then
immediately exits. The syscall-order guarantees that the data is written
to the pipe before the SIGCHLD is sent (or wait(2) returns). However, we
retrieve the SIGCHLD from our main-thread usually (p.join() in our test,
and BuildRoot() in our main code), while the pipe-reading is done from
an API thread. Therefore, we might end up handling the SIGCHLD first
(just imagine a single-threaded CPU that schedules the main task before
the thread). To avoid this race, we can simply synchronize with the
api-thread. Since we already have this synchronization as part of the
api-thread takedown, it is as simple as stopping the api-thread before
continuing with operations.

Lastly, if a write operation to a pipe was issued, we are guaranteed
that a SIGCHLD synchronization across processes is ordered correctly.
Furthermore, the python event-loop also guarantees that stopping an
event-loop will necessarily dispatch all outstanding events. A read is
guaranteed to be outstanding in our race-scenario, so the read will be
dispatched. The only possible problem is `_output_ready()` only
dispatching a maximum of 4096 bytes. This might need to be fixed
separately. A comment is left in place.
2020-08-13 14:02:27 +02:00
..
util jsoncomm: remove destination from send 2020-07-29 02:16:20 +01:00
__init__.py osbuild: extract CLI to prepare for additional entrypoints 2020-04-28 15:39:54 +02:00
__main__.py osbuild: use osbuild_cli directly as main entry 2020-07-17 16:30:46 +01:00
api.py api: prevent early output retrieval 2020-08-13 14:02:27 +02:00
buildroot.py buildroot: ensure /sys/fs/selinux is read-only 2020-08-12 16:52:27 +02:00
loop.py loop: fix FD leak in mknod() 2020-04-21 13:02:29 +02:00
main_cli.py osbuild: unified libdir handling 2020-08-04 09:02:22 +02:00
meta.py meta: also validate the schema for sources 2020-06-02 09:50:14 +02:00
monitor.py monitor: add assembler/stage duration 2020-08-06 16:19:47 +02:00
objectstore.py objectstore: use types.PathLike 2020-07-27 12:50:38 +01:00
pipeline.py api: prevent early output retrieval 2020-08-13 14:02:27 +02:00
remoteloop.py api: remove 'addr' param from message dispatcher 2020-07-29 02:16:20 +01:00
sources.py api: remove 'addr' param from message dispatcher 2020-07-29 02:16:20 +01:00
treesum.py treesum: don't use dir_fd parameter in os.scandir() 2019-11-29 00:45:14 +01:00