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

Chapter 5: Internal Server Error: Connection pool timed out on POST to /subscriptions #146

Closed
oddgrd opened this issue Apr 1, 2022 · 5 comments

Comments

@oddgrd
Copy link

oddgrd commented Apr 1, 2022

Hi. I enjoyed the book and learned a lot already, but I've had a lot of issues with deployment on Digital Ocean App Platform. My first issue was the Out Of Memory error, #71, which I resolved by building the image with a GA workflow and deploying with that image. I originally had some weird issues with deploying the DB, but I resolved it.

However, after successfully deploying the app with the DB, I get a 500 on post requests to /subscriptions. I've checked the env vars in the DO console as instructed here: https://docs.digitalocean.com/products/app-platform/how-to/use-environment-variables/ -> echo $<name-of-environment-variable>, and they are correct and the same as the connection parameters of the database. I've searched through my code, compared it to the book code, the book repo code and some other peoples solutions.

Locally everything is fine and tests pass. The issue seems to be with the connection to the DB in production, as the query fails with Connection pool timed out. The health check passes.
In the DO runtime logs I get the expected output in the app logs:

ADDING A NEW SUBSCRIBER - START  
SAVING NEW SUBSCRIBER DETAILS IN THE DATABASE - START  
SAVING NEW SUBSCRIBER DETAILS IN THE DATABASE - EVENT Failed to execute query: PoolTimedOut  
etc...

In the DO database runtime logs I see no output when sending the request.

My app spec: https://github.com/oddgrd/zero2prod/blob/main/spec.yml
My image builder workflow: https://github.com/oddgrd/zero2prod/blob/main/.github/workflows/push-image.yml
My configuration file: https://github.com/oddgrd/zero2prod/blob/main/src/configuration.rs

I assume the issue here is something simple I have missed or misunderstood, but I'd be grateful if someone could have a look. Great book, thanks!

@LukeMathWalker
Copy link
Owner

Can you try lowering the minimum application log level from info to debug or trace? We might learn something useful there.

@oddgrd
Copy link
Author

oddgrd commented Apr 3, 2022

Hi, thank you for the suggestion. I lowered the log level as suggested, and unfortunately I didn't find the problem. I'm not sure what the preferred way of sharing logs is, but I put logs from the app launch until the end of a /subscribe span in a pastebin. They are quite dense.

As everything works in dev, I assume there must be something wrong with my config in prod, but I cannot see it. I have diverged from your code in the get_configuration function, as the merge function on Config is deprecated (in 0.12). I think I wrote it correctly using the now preferred ConfigBuilder, though.

Other than that I don't think my code diverges from the book (up to the end of chapter 5). I've gone over the code many times to try to find the issue.

Pastebin: https://pastebin.com/aV6CDmE4 (log level trace)

@LukeMathWalker
Copy link
Owner

I don't think that env variable prefixes work the same in 0.12 for config, which is the reason I haven't updated yet.

@oddgrd
Copy link
Author

oddgrd commented Apr 4, 2022

Thank you for helping me troubleshoot. I should've tried changing get_configuration from the start. It was indeed the issue, I changed it and now everything works. I look forward to continuing with the book!

@oddgrd oddgrd closed this as completed Apr 4, 2022
@jgirardet
Copy link

fixed in 0.13
https://github.com/mehcode/config-rs/pull/292/files
you have to explicit the prefix_seperator :

config::Environment::with_prefix("app")
                .prefix_separator("_")
                .separator("__")

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

No branches or pull requests

3 participants