R
Railway•3mo ago
tjh

Garbled response / Gzip issue?

I've been having an issue I can't get to the bottom of, so finally asking here. Context: - I have one Railway project, with several services: one frontend (NextJS, App Router, mainly SSR), one backend service (Django), a database (postgres) - Frontend tries to connect to the backend via private URL, and falls back to public URL if the initial connection fails (like when in client side, or during build) - Frontend calls various APIs, as you'd expect, APIs return JSON - There is no auth between services - The backend has django.middleware.gzip.GZipMiddleware and corsheaders.middleware.CorsMiddleware - The frontend has Cloudflare DNS, which I use to manage the domain - I'm using the new proxy Issue: - I made a change to remove pagination in one of my APIs, and removed the associated pagination logic on the frontend - After deploy, I get the attached error from my frontend during build Things I've tried: - Calling this API on the cmd line/postman works fine, and I get Content-Encoding = gzip in the response headers - Disabling GZipMiddleware in Django, get the same result - Mocking the response - returning hardcoded JSON - get same issue - When I make the hardcoded JSON smaller, it often works - this makes me think it's a Gzipping issue (which triggers when the response is >200 bytes) - Trying the legacy proxy - same result - Setting Accept-Encoding = gzip, deflate, br and Content-Type=application/json on the request in Next - Adding DEFAULT_RENDERER_CLASSES = rest_framework.renderers.JSONRenderer in Django - Praying c18400df-5dee-4fe7-bc56-a98db8d475bd
76 Replies
Percy
Percy•3mo ago
Project ID: c18400df-5dee-4fe7-bc56-a98db8d475bd
tjh
tjhOP•3mo ago
Additional: Another API is called during build that returns an extremely small response (JSON with ~5 entries) and this works fine.
Brody
Brody•3mo ago
do you have an endpoint i could curl to reproduce this issue?
tjh
tjhOP•3mo ago
curl -s -X GET 'https://share-a-podcast-be-prod.up.railway.app/test-new-endpoint/' | jq
curl -s -X GET 'https://share-a-podcast-be-prod.up.railway.app/test-new-endpoint/' | jq
Brody
Brody•3mo ago
is that supported to work?
tjh
tjhOP•3mo ago
ha - yes - what are you seeing?
Brody
Brody•3mo ago
json
tjh
tjhOP•3mo ago
yes
Brody
Brody•3mo ago
can i have an endpoint that reproduces the issue, im not sure what i should be doing with an enpoint that works fine
tjh
tjhOP•3mo ago
yes... I mean that's the issue The endpoint works fine, every time, when called in curl/postman. But in build it gives the output I shared in the first post. This is what I can't understand.
Brody
Brody•3mo ago
during build of your FE?
tjh
tjhOP•3mo ago
yep are you able to see my build logs?
Brody
Brody•3mo ago
how is this url being called?
tjh
tjhOP•3mo ago
one sec, getting the code
tjh
tjhOP•3mo ago
tjh
tjhOP•3mo ago
forgive the terrible loggin
Brody
Brody•3mo ago
did you say you have disabled GZIP on the BE and still got the same garbage response?
tjh
tjhOP•3mo ago
yep - I thought the logs look like printed gzip so I removed GZipMiddleware, same issue
Brody
Brody•3mo ago
is GZIP currently disabled (removed)?
tjh
tjhOP•3mo ago
no i renabled but can disable it again
Brody
Brody•3mo ago
lets leave it for now just trying to parse through these logs
tjh
tjhOP•3mo ago
good luck LMK if I can help
Brody
Brody•3mo ago
i dont see content-encoding = gzip anywhere in these FE build logs, does response.headers.entries() strip that out?
tjh
tjhOP•3mo ago
take a look at the backend logs - I'm logging the headers on inbound requests:
Brody
Brody•3mo ago
right but content-encoding = gzip should be returned as a response header
tjh
tjhOP•3mo ago
yeah agree it's not there but why?
Brody
Brody•3mo ago
curl -I "https://share-a-podcast-be-prod.up.railway.app/test-new-endpoint/"
HTTP/1.1 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Cross-Origin-Opener-Policy: same-origin
Date: Wed, 11 Sep 2024 16:31:23 GMT
Referrer-Policy: same-origin
Server: railway-edge
Vary: Accept-Encoding, origin, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Railway-Request-Id: nmUVBEMHRwKJVioSmvMM1Q_2020806880
curl -I "https://share-a-podcast-be-prod.up.railway.app/test-new-endpoint/"
HTTP/1.1 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Cross-Origin-Opener-Policy: same-origin
Date: Wed, 11 Sep 2024 16:31:23 GMT
Referrer-Policy: same-origin
Server: railway-edge
Vary: Accept-Encoding, origin, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Railway-Request-Id: nmUVBEMHRwKJVioSmvMM1Q_2020806880
misbehaving middleware? but you said it was the same with the middleware removed? either way, can you disable / remove the gzip middleware for now?
tjh
tjhOP•3mo ago
dude sorry, back at keys disabling now
Brody
Brody•3mo ago
for context, curl was showing that it got the gzip response header -
C:\Users\Brody>curl --location -I "https://share-a-podcast-be-prod.up.railway.app/test-new-endpoint/" --header "Accept-Encoding: gzip, deflate, br" --header "Content-Type: application/json"
HTTP/1.1 200 OK
Allow: GET, HEAD, OPTIONS
Content-Encoding: gzip
Content-Length: 826
Content-Type: application/json
Cross-Origin-Opener-Policy: same-origin
Date: Wed, 11 Sep 2024 16:40:05 GMT
Referrer-Policy: same-origin
Server: railway-edge
Vary: Accept-Encoding, origin, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Railway-Request-Id: 1bO2oXJ6Sn-rCTujPm4rCw_882434190
C:\Users\Brody>curl --location -I "https://share-a-podcast-be-prod.up.railway.app/test-new-endpoint/" --header "Accept-Encoding: gzip, deflate, br" --header "Content-Type: application/json"
HTTP/1.1 200 OK
Allow: GET, HEAD, OPTIONS
Content-Encoding: gzip
Content-Length: 826
Content-Type: application/json
Cross-Origin-Opener-Policy: same-origin
Date: Wed, 11 Sep 2024 16:40:05 GMT
Referrer-Policy: same-origin
Server: railway-edge
Vary: Accept-Encoding, origin, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Railway-Request-Id: 1bO2oXJ6Sn-rCTujPm4rCw_882434190
tjh
tjhOP•3mo ago
this is what led me to think it might be something to do with the proxy communicating with the end point directly works
Brody
Brody•3mo ago
the proxy doesnt touch any of these headers afaik
tjh
tjhOP•3mo ago
Railway Help Station
The new proxy is stripping the Accept-Encoding header
On the legacy proxy, requests correctly returned the gzipped response when browsers send the Accept-Encoding: gzip, deflate, br header. However, this does not work on the new proxy. It appears that the Accept-Encoding header is stripped before reaching my server.
tjh
tjhOP•3mo ago
aware this is now solved, but wondering if related?
Brody
Brody•3mo ago
well besides the headers it does touch, you know what i mean lol
tjh
tjhOP•3mo ago
btw, I noticed that when I deploy the backend, I have to commit/push to force a rebuild on my frontend, rather than just trigging a deploy from last commit
Brody
Brody•3mo ago
Hello all, we have pushed a change to our proxy, we no longer strip out that header!
what happens when you do deploy from last commit?
tjh
tjhOP•3mo ago
I know, but just wondering if could be a related thing? I'll show you
Brody
Brody•3mo ago
at this time, i dont think so
tjh
tjhOP•3mo ago
backend is deployed frontend deploying now with deploy from last commit
Brody
Brody•3mo ago
i can confirm with postman the BE response is no longer gzipped, no encoding header and resonse body is larger
tjh
tjhOP•3mo ago
agreed, see the same
Brody
Brody•3mo ago
interesting
tjh
tjhOP•3mo ago
ok - frontend built correctly with trigger last commit but same issue
Brody
Brody•3mo ago
lets use the private domain then
tjh
tjhOP•3mo ago
in build?
Brody
Brody•3mo ago
yeah
No description
tjh
tjhOP•3mo ago
oooh have you just opted me in fine if you have
Brody
Brody•3mo ago
yeah, just trying to move fast here, i will ask next time
tjh
tjhOP•3mo ago
no don't worry, just wonderd didn't remember doing it and I've been battling this for 1.5 days... starting to forget what life was like before this bug I think it's worked either way - being able to use private urls in build is a win shall I renable gzip on the BE?
Brody
Brody•3mo ago
oh, it worked... i was kinda hoping it wouldnt
tjh
tjhOP•3mo ago
yeah, as is we haven't learnt anything
Brody
Brody•3mo ago
exactly
tjh
tjhOP•3mo ago
just that the new builder works for some reason enabling gzip
Brody
Brody•3mo ago
hold on not yet please
tjh
tjhOP•3mo ago
oops aborted the build
Brody
Brody•3mo ago
oh wait, this is a production site, can you afford to keep this offline as we debug?
tjh
tjhOP•3mo ago
yes all my user will be ok with it
Brody
Brody•3mo ago
are you sure? we could spin up a dev env in railway
tjh
tjhOP•3mo ago
yes don't worry
Brody
Brody•3mo ago
alright, sounds good, but yeah lets keep gzip off for now, it eliminates variables
tjh
tjhOP•3mo ago
anything I can do to help debug? I would like to remove the hard-coded response, and replace with DB query ok for me to try? I'll leave gzip off
Brody
Brody•3mo ago
yeah thats fine
tjh
tjhOP•3mo ago
that's deployed redeploying FE
Brody
Brody•3mo ago
well my fridge doesn't cool anymore, I gotta go AFK while I transfer everything to another fridge outside
tjh
tjhOP•3mo ago
good luck I'm going to try renabling gzip while you're fridging FYI database connection worked
Brody
Brody•3mo ago
they didn't before?
tjh
tjhOP•3mo ago
ah, it was just one of many things I've been trying to debug the issue - hardcoding the json response in my backend was looking for special characters/fixing the size of the repsonse, etc gzip works
Brody
Brody•3mo ago
okay I have some more things I'd like to try when I'm back
tjh
tjhOP•3mo ago
where are we on the fridge outage, Brody? P1? Users affected? Is there an incident channel we should join?
Brody
Brody•3mo ago
there's an incident? I thought we left off in a working state with the new builder?
tjh
tjhOP•3mo ago
was a joke about your fridge, ignore anyway, new builder working - I'm back to coding, thanks for your help
Brody
Brody•3mo ago
oh I thought you were serious 😅
tjh
tjhOP•3mo ago
rarely
Brody
Brody•3mo ago
I thought you were like, screw your fridge, help me with this gzip stuff
tjh
tjhOP•3mo ago
haha would never priotise work above food
Brody
Brody•3mo ago
I'll be back at the computer as soon as I finish eating and moving the food to the other fridge alright, i am back
Want results from more Discord servers?
Add your server