Skip to content

Commit

Permalink
appservice: Replace nginx with aiohttp reverse proxy
Browse files Browse the repository at this point in the history
nginx does not get along well with unavailable proxy_pass targets -- as
soon as one session pod unexpectedly goes away (crashes, idle timeouts,
networking flakes), it errors out and no session routes can be resolved
any more. There are workarounds [1], but I can't get them to work
properly. Also, nginx does not allow us to hook into (dis)connection
events to implement the session status API (see issue #28).

So it's finally time to grow to something more flexible. Rewrite
multiplexer.py using aiohttp [2], which now handles both our own session
control API as well as the dynamic reverse proxying to the session pods.

This actually behaves *slower* than with nginx, resulting in lagging/missing
CSS in the browser. This should still be considered as a PoC, but at least
there are fewer moving parts and an easier-to-understand architecture now.

Check behaviour with broken session pods in the tests: Crash a session
pod, and validate that the other sessions still behave correctly.

Fixes #36

[1] https://sandro-keil.de/blog/let-nginx-start-if-upstream-host-is-unavailable-or-down/
[2] https://docs.aiohttp.org/en/stable/index.html
  • Loading branch information
martinpitt committed Sep 15, 2022
1 parent 16a55e5 commit 65c7d43
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 201 deletions.
5 changes: 1 addition & 4 deletions appservice/Containerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
FROM debian:bookworm

RUN apt-get update && \
apt-get install -y python3 python3-redis nginx curl inetutils-ping procps && \
apt-get install -y python3 python3-redis python3-aiohttp curl inetutils-ping procps && \
apt-get clean && \
rm /var/lib/apt/lists/*dists*

# allow unprivileged container user to run nginx and change configuration
RUN chmod -R a+rw /etc/nginx/ /var/lib/nginx/ /var/log/nginx/ /run

COPY *.py /usr/local/bin/

CMD python3 /usr/local/bin/multiplexer.py
Loading

0 comments on commit 65c7d43

Please sign in to comment.