Server-Side event in traefik? nginx ok - traefik => internal server error

Hi,

I'm trying to set a server-side event correctly to no avail.
I have a Django server that has a URL that sends sse, I can proxy easily with nginx with this simple conf:

server {
  listen 80;
  server_name _ ;
  charset utf-8;
  client_max_body_size 20M;

  location / {
    proxy_pass http://django:8000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
  }
}

In traefik using docker labels I set:

    labels:
       - "traefik.enable=true"
       - "traefik.http.routers.dj.rule=Host(`$HOST_ADK`)"
       - "traefik.http.routers.dj.entrypoints=web"
       - "traefik.http.routers.dj.service=dj"
       - "traefik.http.services.dj.loadbalancer.server.port=8000" 
       #- "traefik.http.routers.dj.middlewares=compress-no-stream"
       #- "traefik.http.middlewares.compress-no-stream.compress=true"
       #- "traefik.http.middlewares.compress-no-stream.compress.excludedcontenttypes=text/event-stream"

This resolve to internal server error that I cannot further debug.

Any hint on what's the correct configuration su make Server-Side event work?

Sandro

1 Like

Some more info to help debug the problem. The error I get in the application is "took too long to shut down and was killed." or precisely:

Application instance <Task pending name='Task-2' coro=<StaticFilesWrapper.__call__() running at /home/sandro/.pyenv/versions/3.8.6/envs/fiverr-traefik/lib/python3.8/site-packages/channels/staticfiles.py:44> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fe3092690d0>()]>> for connection <WebRequest at 0x7fe309b68640 method=GET uri=/adrenalinik/sse/channels/sse-example/ clientproto=HTTP/1.1> took too long to shut down and was killed.
Exception inside application: [Errno -3] Temporary failure in name resolution
Traceback (most recent call last):
  File "/home/sandro/.pyenv/versions/3.8.6/envs/fiverr-traefik/lib/python3.8/site-packages/channels/generic/http.py", line 81, in http_request
    await self.handle(b"".join(self.body))
  File "/home/misc/src/hg/thunder/siti/adk/fiverr-traefik/apps/adrenalinik/consumers.py", line 71, in handle
    await asyncio.sleep(4)
  File "/home/sandro/.pyenv/versions/3.8.6/lib/python3.8/asyncio/tasks.py", line 656, in sleep
    return await future
asyncio.exceptions.CancelledError

I guess "Temporary failure in name resolution" is a good candidate for the culprit, but I'm not able to make good profit of it. Rememnber: when passing via nginx it does work correctly.

1 Like

I'm honestly baffled by the total silence around this issue. I even posted a question on StackOverflow and an issue on github.

I thought there were quite a lot of people using Server-Sent events and the fact that there's a compress option to cope with text/stream-data makes me think it's a well-supported setup.

I'd like at least to understand if others have managed to proxy server-sent events.

BTW: am I correct in thinking that if I don't use compress middleware, there's no compression at all and ideally it should work? ie: I only need the option that excludes compression if I explicitely set compression.

Thanks

1 Like

@sandroden: I am also highly interested in this. I tested SSE with Traefik v2 and it appears to work fine.
I don't know whether compression is enabled for this test.

Related:

The compress option may indeed have something to do with SSE, take a look at this article:

SOLVED. It turns out I was sending 2 identical headers and that makes Traefik complain.
More explanation in the issue (that I couldn't comment as I realized when it was already frozen...)

*:slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.