Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected status code when backend timeout occurs #584

Open
teodorescuserban opened this issue Dec 11, 2024 · 6 comments · May be fixed by #589
Open

unexpected status code when backend timeout occurs #584

teodorescuserban opened this issue Dec 11, 2024 · 6 comments · May be fixed by #589

Comments

@teodorescuserban
Copy link

I am using souin cache as caddy module.

More details are here.

I am getting status code 200 with the body "Internal server error" when the backend does not respond before the timeout.backend.

I would expect at least a 504.

darkweak added a commit that referenced this issue Dec 22, 2024
@darkweak darkweak linked a pull request Dec 22, 2024 that will close this issue
@darkweak
Copy link
Owner

@teodorescuserban can you try with the latest commit (as mentioned here: #585 (comment)) please? 🙏

@teodorescuserban
Copy link
Author

I'd happily try it, but I need a correct commit sha I think.

65.45 2025/01/22 14:34:36 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -v github.com/darkweak/souin@e5c1440eb3a0c1c6832488a6605e842c09ecc04a github.com/caddyserver/caddy/[email protected]
79.74 go: github.com/darkweak/souin@e5c1440eb3a0c1c6832488a6605e842c09ecc04a: invalid version: unknown revision e5c1440eb3a0c1c6832488a6605e842c09ecc04a

@teodorescuserban
Copy link
Author

With the new commit shas provided in #585 I was able to build and test. It looks better.

I set the backend timeout for testing to 30s.

cache {
	timeout {
		backend 30s
		cache 5s
	}
}

I am getting the expected 504 status code. However, there is something amiss.

In caddy, I have configured

	handle_errors 5xx {
		respond `{"code":"{err.status_code}","message":"{err.status_text}"}`
	}

when I am forcing the reverse_proxy to expire before the cache backend timeout by setting

	reverse_proxy {
		...
		transport http {
			response_header_timeout 10s
		}
	}

I am also getting the expected {"code":"504","message":"Gateway Timeout"} with the expected headers:

...
content-type: application/json
...
cache-status: cache; fwd=uri-miss; key=/v3/viewLog?day=1; detail=SERVE-HTTP-ERROR

However, when the cache backend is hit first, I do get 504 status code, but I get a plaintext response Internal server error
with different headers:

...
content-type: text/plain; charset=utf-8
...
cache-status: hpc; fwd=bypass; detail=DEADLINE-EXCEEDED

Now, I don't mind the cache-status header differences, but I do need to provide a json response, not a plaintext response.

Any ideas, @darkweak?

cc @francislavoie - perhaps modules order? the cache module is called inside a route, but I cant add handle_response inside that route... :\

@francislavoie
Copy link

I don't know what you mean. handle_response is an option for reverse_proxy, it's not a directive of its own. You can use intercept to have a general-purpose handle_response (for non-reverse_proxy response writing).

@teodorescuserban
Copy link
Author

I don't know what you mean. handle_response is an option for reverse_proxy, it's not a directive of its own. You can use intercept to have a general-purpose handle_response (for non-reverse_proxy response writing).

Thank you for replying, @francislavoie and sorry for the typo. I meant handle_errors, as [correctly] pasted above in the config excerpt.

@francislavoie
Copy link

Ah, yeah handle_errors is special, it's a separate route context, must go top-level and not inside other routes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants