Skip to content

Commit

Permalink
Multi-worker-docker-container: disable log buffering (#16919)
Browse files Browse the repository at this point in the history
Background: we have a `matrixdotorg/synapse-workers` docker image, which
is intended for running multiple workers within the same container. That
image includes a `prefix-log` script which, for each line printed to
stdout or stderr by one of the processes, prepends the name of the
process.

This commit disables buffering in that script, so that lines are logged
quickly after they are printed. This makes it much easier to understand
the output, since they then come out in a natural order.
  • Loading branch information
richvdh authored Mar 13, 2024
1 parent 9b5eef9 commit 92f2069
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/16919.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Multi-worker-docker-container: disable log buffering.
7 changes: 5 additions & 2 deletions docker/prefix-log
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# prefix-log command [args...]
#

exec 1> >(awk '{print "'"${SUPERVISOR_PROCESS_NAME}"' | "$0}' >&1)
exec 2> >(awk '{print "'"${SUPERVISOR_PROCESS_NAME}"' | "$0}' >&2)
# '-W interactive' is a `mawk` extension which disables buffering on stdout and sets line-buffered reads on
# stdin. The effect is that the output is flushed after each line, rather than being batched, which helps reduce
# confusion due to to interleaving of the different processes.
exec 1> >(awk -W interactive '{print "'"${SUPERVISOR_PROCESS_NAME}"' | "$0 }' >&1)
exec 2> >(awk -W interactive '{print "'"${SUPERVISOR_PROCESS_NAME}"' | "$0 }' >&2)
exec "$@"

0 comments on commit 92f2069

Please sign in to comment.