Media doesn't sync behind Caddy – Error 303 when downloading media, upload works fine

Hello,

For almost a year now I’ve been using a local anki sync server. No problem whatsoever when using the IP of the server directly, even now. However, if I try to run it behind Caddy, the reverse proxy I use for my services, I get a HttpError 303 “stream failure” when it tries to download media files from the server, even though uploading works fine. Besides media, everything else gets synced correctly.

Logs show that the server receives /sync/chunk requests forwarded by Caddy and processes them properly until, at some point, Caddy fails at forwarding one due to reading: read tcp [caddy]->[anki-sync-server]: read: connection reset by peer, which triggers a /sync/abort by the syncing client.

I’m not very experienced in reverse proxies, so I would really appreciate any help. I can post the full logs of both the server and Caddy if needed.

Thanks a lot in advance.

I have no experience with custom sync servers or caddy. But I stumbled upon this today: Sync Server - Anki Manual.

Maybe something there could help you?

1 Like

I tried setting MAX_SYNC_PAYLOAD_MEGS to 10000, but I’m still getting the same error.

In case it proves any useful, these are the logs of the last two requests from Caddy:

Logs

192.168.10.10 is Caddy, 192.168.8.10 is anki-sync and 192.168.10.26 is my device.

{"level":"debug","ts":1747091055.7676713,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"192.168.8.10:30701","duration":0.009912883,"request":{"remote_ip":"192.168.10.26","remote_port":"49359","client_ip":"192.168.10.26","proto":"HTTP/1.1","method":"POST","host":"anki.ego1st.me","uri":"/sync/chunk","headers":{"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["anki.ego1st.me"],"Anki-Sync":["{\"v\":11,\"k\":\"\",\"c\":\"25.02,7ba143ba,ios\",\"s\":\"\"}"],"Content-Type":["application/octet-stream"],"Accept":["*/*"],"User-Agent":[""],"X-Forwarded-For":["192.168.10.26"]},"transfer_encoding":["chunked"],"tls":{"resumed":false,"version":771,"cipher_suite":49195,"proto":"","server_name":"anki.ego1st.me"}},"headers":{"Date":["Mon, 12 May 2025 23:04:15 GMT"],"Anki-Original-Size":["1259877"]},"status":200}

{"level":"warn","ts":1747091055.7695298,"logger":"http.handlers.reverse_proxy","msg":"aborting with incomplete response","upstream":"192.168.8.10:30701","duration":0.009912883,"request":{"remote_ip":"192.168.10.26","remote_port":"49359","client_ip":"192.168.10.26","proto":"HTTP/1.1","method":"POST","host":"anki.ego1st.me","uri":"/sync/chunk","headers":{"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["anki.ego1st.me"],"Anki-Sync":["{\"v\":11,\"k\":\"\",\"c\":\"25.02,7ba143ba,ios\",\"s\":\"\"}"],"Content-Type":["application/octet-stream"],"Accept":["*/*"],"User-Agent":[""],"X-Forwarded-For":["192.168.10.26"]},"transfer_encoding":["chunked"],"tls":{"resumed":false,"version":771,"cipher_suite":49195,"proto":"","server_name":"anki.ego1st.me"}},"error":"reading: read tcp 192.168.10.10:35878->192.168.8.10:30701: read: connection reset by peer"}

What follows below is just a list of things that I found – it might give you ideas or even help, but it also might be useless.

  1. Maybe something you can check: Does it work without caddy, using the server directly?
  2. Considering you’re having issues with downloading media, maybe there is a timeout that is set too short? Apparently the Caddyfile contains something like
handle {
  reverse_proxy http://ADDRESS:PORT {
    transport http {
      read_timeout 60s
      write_timeout 60s
    }
  }
}

So if yours contains something similar, maybe try to increase the timeouts?

  1. You’re getting read: connection reset by peer. Doesn’t that mean that your Anki server (so not caddy) closed the connection earlier than expected? Maybe you can adjust timeouts here as well? Or something like “keep-alive”?
  2. No idea what any of those things mean, but apparently header_up can be useful sometimes when it comes to media: reverse_proxy (Caddyfile directive) — Caddy Documentation.
  3. Just because it’s so similiar regarding the error: Maybe check the things Dae mentioned in Get HTTPError() code:303 when I try to sync (even though it’s not related to custom sync servers or caddy).

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