summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2024-03-13 17:21:37 +0000
committerGitHub <noreply@github.com>2024-03-13 17:21:37 +0000
commit92f20696273ca88c24d1dcdd738bd0f1d4be9e61 (patch)
tree3266b93e37633af52e2916ce1648a4ce882c7490
parentBump ruff from 0.1.14 to 0.3.2 (#16994) (diff)
downloadsynapse-92f20696273ca88c24d1dcdd738bd0f1d4be9e61.tar.xz
Multi-worker-docker-container: disable log buffering (#16919)
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.
Diffstat (limited to '')
-rw-r--r--changelog.d/16919.misc1
-rwxr-xr-xdocker/prefix-log7
2 files changed, 6 insertions, 2 deletions
diff --git a/changelog.d/16919.misc b/changelog.d/16919.misc
new file mode 100644
index 0000000000..2c76f25379
--- /dev/null
+++ b/changelog.d/16919.misc
@@ -0,0 +1 @@
+Multi-worker-docker-container: disable log buffering.
diff --git a/docker/prefix-log b/docker/prefix-log
index 0e26a4f19d..32dddbbfd4 100755
--- a/docker/prefix-log
+++ b/docker/prefix-log
@@ -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 "$@"