guess_wh0
guess_wh0
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
--- Question to you experts: Is there a certain value for pool_size (= nr of connections) you would recommend to use? Why?
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
Actually, it turns out that the crash was caused for different reasons at different places. 1. Rocket seems to decide how many connections to create. More specifically, rocket_sync_db_pools. That package "defaults to the configured number of workers * 4", which seems to be >100 on railway. I assume "workers" means "CPUs", but feel free to correct me if you know more than I do 🙂 Thus, on Railway, there were simply too many connections. 2. Locally, when trying to connect to the Railway-DB, my code only tries to create 32 connections (maybe because of 8 CPUs?). - Thus, I was always able to connect to my local DB - However, connecting to the Railway-DB failed because creating 32 connections within the default timeout of 5s wasn't possible. - Surprisingly, diesel didn't do anything wrong this time (at least according to my understanding) - Limiting pool_size and timeout allowed me to connect again.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
The website's back up!! 🎉
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
I'll write an update when there's new information
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
Well that's unfortunate as it'll mean a lot of rewriting. However, if it's the main way to get the app running again, I'll have to do it. Thank you for your suggestion regarding sqlx. I'll perform 1-2 more tests in hopes of finding the bug somewhere, but if they turn out unhelpful, I'll work on replacing diesel with sqlx.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
I understand that. The strange thing is that: 1. it used to work just fine and I haven't changed anything about my setup (though maybe the package-manager did some cheating) 2. it still works with my local DB. This leads me to believe that the code isn't just straight out wrong in every regard but that there has to be some interaction that results in this particular issue.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
It feels strange that I'm able to connect to my local DB but not the Railway one. Could it be that somehow they're set up differently? Allowing/disallowing different things?
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
Okaaaay, so after some digging, it seems .attach(DbConn::fairing()) is the problematic line (see rocket()-function). However, I don't see where I'm doing anything dangerous. DbConn is just a rocket guard type and looks exactly like it's shown in the docs.
/// Connection to the server's [diesel]-PostgreSQL-database.
#[database("voteon_date_db")]
pub struct DbConn(diesel::PgConnection);
/// Connection to the server's [diesel]-PostgreSQL-database.
#[database("voteon_date_db")]
pub struct DbConn(diesel::PgConnection);
(Plus, I've added some methods to the struct. However, these 1. do not generate new connections and 2. aren't called until a route is requested.)
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
I feel the same way 😅
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
Oh right, here's the full backtrace. The part of my code it highlights (voteon_date/backend/src/main.rs:53:1) doesn't seem particularly helpful. That line is just the closing bracket of the rocket() (=main) function.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
I did, it's run only once. It seems to be async though – or the error is occuring later – as ALL print-statements are executed, even the ones at the very end of the function.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
See this comment for what the establish_manual_connection()-function looks like.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
I did, but that cuts off all database-functionality, even with my local DB. That code is directly copied from Diesel's Getting Started guide by diesel's code, so I don't think I've made an error there.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
Only once. It's basically the main()-function of the server. See last reply to @Brody .
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
I get what you're saying, but haven't yet found out what could be the issue. The main function (see above) is the only place where I open a connection, and it's only called once. Of course, there may be some dark magic going on in the background that I don't know about.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
I tried disabling the migrations (see reducid code-sample) but unfortunately the error persists. Makes me think it's something else.
/// main function
fn rocket() -> _ {
// Automatically run db-migrations
let mut db_conn = database::establish_manual_connection();
/* db_conn
.run_pending_migrations(MIGRATIONS)
.unwrap_or_else(|e| panic!("Error running migrations: {}", e)); */

let mut rocket_build = rocket::build()
.attach(DbConn::fairing())
.attach(Template::fairing())
.mount("/", api::dev_routes())
.mount("/swagger", make_swagger_ui(&api::open_api::get_docs()));

rocket_build
}
/// main function
fn rocket() -> _ {
// Automatically run db-migrations
let mut db_conn = database::establish_manual_connection();
/* db_conn
.run_pending_migrations(MIGRATIONS)
.unwrap_or_else(|e| panic!("Error running migrations: {}", e)); */

let mut rocket_build = rocket::build()
.attach(DbConn::fairing())
.attach(Template::fairing())
.mount("/", api::dev_routes())
.mount("/swagger", make_swagger_ui(&api::open_api::get_docs()));

rocket_build
}
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
ChatGPT tells me this: However, Diesel itself doesn't directly handle TLS (Transport Layer Security) or encryption. The use of TLS in a Rust application using Diesel would typically depend on the database server and the connection settings you use when configuring your database connection. For example, if you are connecting to a PostgreSQL database using Diesel, the TLS or SSL connection would be configured through the PostgreSQL connection settings rather than directly within Diesel. You probably know best though what is and isn't possible. I've checked the API docs for diesel, but I don't recognize anything there.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
I'm not sure. Any idea how to find out? The only thing I can find is that Rocket supports it.
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
No description
126 replies
RRailway
Created by guess_wh0 on 1/25/2024 in #✋|help
Issues connecting to Postgres Database after redeploying service
That'll take a few hours though since I need to get home first
126 replies