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

Connection flooding until reaching max_connections and then panic #2340

Closed
2 tasks done
andrejohansson opened this issue Mar 25, 2020 · 13 comments
Closed
2 tasks done

Comments

@andrejohansson
Copy link

andrejohansson commented Mar 25, 2020

Setup

Versions

  • Rust: 1.41.1 (f3e1a954d 2020-02-24)
  • Diesel: 1.4.4 (see below for full Cargo.toml dependencies)
  • Database: postgres (PostgreSQL) 12.2 (Ubuntu 12.2-2.pgdg18.04+1)
  • Operating System
    • client: Windows 10 Pro, version 1909, build 18363.720
    • database server: Ubuntu 18.04.4 LTS (GNU/Linux 5.0.0-1032-azure x86_64) (running as a vm in azure)

Feature Flags

  • diesel: ["postgres", "chrono", "r2d2"]

Problem Description

This is a move of this issue, in order to get help to find the source of the problem.

What are you trying to accomplish?

Use actix web server with juniper+wundergraph graphql api endpoint in a stable manner.

What is the expected output?

That if I set my connection pooling to 8 connections, it should remain at 8 connections.

What is the actual output?

Idle connections get created a lot until MAX_CONNECTIONS is reached, then my app cannot connect anymore and the database gets unavailable for further use until a restart or killing connections manually.

Running select * from pg_stat_activity; shows that idle connections is filling up. But I also found that one query got spammed: SET CLIENT_ENCODING TO 'UTF8'. According to @weiznich this is some internal query run by diesel on connection setup.

image

Are you seeing any additional errors?

As a result of hitting MAX_CONNECTIONS then the app threads starts to fail and panic (as expected).

Steps to reproduce

Really not sure about this, this is my actix web server initialization code:

    let query = Query::<MyContext<DBConnection>>::default();
    let mutation = Mutation::<MyContext<DBConnection>>::default();
    let schema = Schema::new(query, mutation);

    let schema = Arc::new(schema);
    let pool = Arc::new(db::init_pool(&s.database_url));
    let data = graphql::handler::AppState { schema, pool };

    HttpServer::new(move || {
        let auth = HttpAuthentication::bearer(validator);
        let s2 = settings::SETTINGS.read().unwrap();

        App::new()
            .data(data.clone())
            // enable logger
            .wrap(middleware::Logger::default())
            // handle cors origins
            .wrap(
                Cors::new() 
                    .allowed_origin(&s2.frontend_url)
                    .allowed_origin(&s2.backend_url)
                    .allowed_origin("http://localhost:8000")
                    .allowed_origin("http://localhost:3000")
                    .allowed_methods(vec!["GET", "POST"])
                    .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
                    .allowed_header(http::header::CONTENT_TYPE)
                    .max_age(3600)
                    .finish(),
            )
            // graphql service and the graphiql editor            
            .service(web::resource("/graphql")
                //.wrap(auth.clone())
                .route(web::post().to(graphql))
            )
            // serve a api att the /api endpoint
            .service(
                web::scope("/api")
                    .wrap(auth.clone())
                    .route("/events", web::get().to(events))
            )            
            // serve static files i the root
            .service(fs::Files::new("/", "./static").index_file("index.html"))

And this is my connection setup code:

use log::*;
use diesel::pg::PgConnection;
use diesel::r2d2::{ConnectionManager, Pool};
use crate::settings;

pub fn init_pool(database_url: &str) -> Pool<ConnectionManager<PgConnection>> {
    let manager = ConnectionManager::<PgConnection>::new(database_url);
    Pool::builder()
        .max_size(8)
        .build(manager)
        .expect(&format!("Error connecting to {}", &database_url))        
}

Other than this, I am not doing anything manually regarding database queries or access. It´s all handled by the generated diesel/juniper/wundergraph classes.

Questions/hypothesis

I'm new to all of this (rust, diesel, juniper, wundergraph and postgres) so no question/answer is too stupid. I'm a bit stuck of how to investigate this further so all help and suggestions are welcome.

One hypothesis I have (but I don´t know how to test) is that when I'm developing, I'm opening connections, then I exit my app with ctrl + c. Perhaps this is the cause of the lingering connections? If so, is there anyway I can get my app to exit gracefully and shut down the connections on exit. Or is this already handled automatically by r2d2?

My other hypothesis was that when executing a graphql query that was nested it somehow triggered opening of a lot connections. But why should this ignore the pool limits and not wait? Could here be some nasty spooky threading issue?

I've tried to configure postgresql to cleanup connections that have been idle for 5 minutes using:

alter system set idle_in_transaction_session_timeout='5min';

but that is more of a emergency solution than a remedy.

All help is much appreciated.

Checklist

active toolchain
----------------

stable-x86_64-pc-windows-msvc (default)
rustc 1.41.1 (f3e1a954d 2020-02-24)

Cargo.toml

[dependencies]
# settings
config = "0.10.1"
lazy_static = "1.4.0"

# dev tools
listenfd = "0.3.3"
env_logger = "0.7.1"
futures = "0.3.4"
failure = "0.1.7"

# web (server side)
actix-web = "2.0.0"
actix-rt = "1.0.0"
actix-files = "0.2.1"
actix-cors = "0.2.0"
actix-session = "0.3.0"
actix-web-httpauth = "0.4.1"
jsonwebtokens = "1.0.0-alpha.12"
log = "0.4.8"

# graphql
juniper = "0.14.2"
wundergraph = {version = "0.1.2", features = ["postgres", "chrono", "debug"]}

# database
diesel = { version = "1.4.3", features = ["postgres", "chrono", "r2d2"] }
diesel-derive-enum =  { version = "0.4.4", features = ["postgres"] }

# Needed for Postgres.
openssl = "*"
openssl-probe = "0.1.2"
dotenv = "0.15.0"

# Date and time
chrono = { version = "0.4.10", features = ["serde"] }
ics = "0.4.2"

# Serlization
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
json = "*"
rustc-serialize = "0.3.24"

postgresql-12-main.log

2020-03-25 14:36:50.230 UTC [74724] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:36:50.234 UTC [74726] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:36:50.234 UTC [74725] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:36:51.255 UTC [74727] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:36:51.255 UTC [74728] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:36:51.258 UTC [74729] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:36:52.277 UTC [74731] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:47:20.229 UTC [76061] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:47:20.230 UTC [76059] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:47:20.240 UTC [76060] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:47:21.264 UTC [76064] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:47:21.267 UTC [76063] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:47:21.361 UTC [76062] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:47:22.280 UTC [76070] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:47:22.280 UTC [73463] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:57:50.231 UTC [77468] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:57:50.246 UTC [77470] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:57:50.279 UTC [77471] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:57:51.271 UTC [77472] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:57:51.306 UTC [77473] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:57:51.307 UTC [74730] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:57:52.290 UTC [77474] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 14:57:52.319 UTC [77475] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 15:08:20.230 UTC [78745] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 15:08:20.233 UTC [78746] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 15:08:20.243 UTC [77469] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
2020-03-25 15:08:21.261 UTC [78747] andreadmin@wedding LOG:  could not receive data from client: Connection reset by peer
@weiznich
Copy link
Member

I've played a bit around with this, but I've not found anything that could cause this. What follows is just a list of things I've tried/looked at.

  • First of all this cannot be a wundergraph/juniper issue as wundergraph only has access to a reference to a single connection per request, at any point of time. Therefore it cannot retain that connection in any way or get another one.
  • I've then tried to close my application by Ctrl+C and looked if the connections were gone. In fact they are gone, but I use linux as operation system, so you may want to try that on windows as well.
  • From a diesel point of view: The connection pool controls when a connection should be opened or closed. We only provide functionality to create a connection and to check if it's broken. The corresponding code is here. Beside of that the pool only returns a reference like type (PooledConnection) if you call pool.get(), so I don't see how we could leak connections there.

That said I'm out of idea's what else could be tried here.

(I've checked the behaviour locally with my own wundergraph/juniper/actix/diesel project, it does not happen there)

@andrejohansson
Copy link
Author

Thanks for your effort.

I'm thinking if I might have to test to bring up a managed azure postgresql instance and see if that´s something different. Perhaps Azure does something interesting (i´ve experienced it before in other situations with sql server). That their networking solutions does weird stuff with connections.

But usually they are on the other side, i.e. terminating idle connections to save resources.

@andrejohansson
Copy link
Author

Gathering some more clues, I saw these error logs when running locally (client on windows, server on ubuntu on azure):

[2020-03-29T16:21:22Z ERROR r2d2] server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

[2020-03-29T16:21:24Z DEBUG wundergraph::query_builder::selection] Query { sql: "SELECT \"persons\".\"id\", \"persons\".\"firstname\", \"persons\".\"lastname\", \"persons\".\"gender\", \"persons\".\"side\", \"persons\".\"year_of_birth\", \"persons\".\"address_id\", \"persons\".\"address_id\",  NULL ,  NULL  FROM \"persons\"", binds: [] }
[2020-03-29T16:21:24Z INFO  actix_web::middleware::logger] 127.0.0.1:57237 "POST /graphql HTTP/1.1" 200 37857 "http://localhost:3000/admin/guestlist" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0" 0.215849
[2020-03-29T16:21:30Z DEBUG wundergraph::query_builder::selection] Query { sql: "SELECT \"persons\".\"id\",  NULL ,  NULL ,  NULL ,  NULL ,  NULL ,  NULL ,  NULL ,  NULL ,  NULL  FROM \"persons\" WHERE \"persons\".\"firstname\" = $1 AND \"persons\".\"lastname\" = $2", binds: ["André", "Johansson"] }
[2020-03-29T16:21:30Z DEBUG wedding::domain::party::model] Query { sql: "SELECT \"rel_persons_parties\".\"person_id\",  NULL ,  NULL , \"rel_persons_parties\".\"party_id\" FROM \"rel_persons_parties\" WHERE \"rel_persons_parties\".\"person_id\" IN ($1)", binds: [Some(2)] }
[2020-03-29T16:21:30Z DEBUG wedding::domain::party::model] Query { sql: "SELECT \"rel_persons_parties\".\"party_id\",  NULL , \"rel_persons_parties\".\"person_id\",  NULL  FROM \"rel_persons_parties\" WHERE \"rel_persons_parties\".\"party_id\" IN ($1)", binds: [Some(74)] }
[2020-03-29T16:21:30Z DEBUG wedding::domain::invitation::model] Query { sql: "SELECT \"invitations\".\"person_id\", \"invitations\".\"id\", \"invitations\".\"rsvp\",  NULL , \"invitations\".\"event_id\" FROM \"invitations\" WHERE \"invitations\".\"person_id\" IN ($1, $2, $3, $4, $5, $6)", binds: [Some(183), Some(184), Some(3), Some(4), Some(1), Some(2)] }
[2020-03-29T16:21:30Z DEBUG wedding::domain::event::model] Query { sql: "SELECT \"rel_events_response_options\".\"event_id\", \"rel_events_response_options\".\"id\",  NULL , \"rel_events_response_options\".\"response_option_id\" FROM \"rel_events_response_options\" WHERE \"rel_events_response_options\".\"event_id\" IN ($1, $2, $3, $4, $5, $6, $7)", binds: [Some(16), Some(10), Some(1), Some(15), Some(14), Some(17), Some(18)] }       
[2020-03-29T16:21:31Z INFO  actix_web::middleware::logger] 127.0.0.1:57245 "POST /graphql HTTP/1.1" 200 12790 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0" 0.640007
[2020-03-29T16:21:31Z DEBUG wundergraph::query_builder::selection] Query { sql: "SELECT \"persons\".\"id\",  NULL ,  NULL ,  NULL ,  NULL ,  NULL ,  NULL ,  NULL ,  NULL ,  NULL  FROM \"persons\" WHERE \"persons\".\"firstname\" = $1 AND \"persons\".\"lastname\" = $2", binds: ["André", "Johansson"] }
[2020-03-29T16:21:31Z DEBUG wedding::domain::party::model] Query { sql: "SELECT \"rel_persons_parties\".\"person_id\",  NULL ,  NULL , \"rel_persons_parties\".\"party_id\" FROM \"rel_persons_parties\" WHERE \"rel_persons_parties\".\"person_id\" IN ($1)", binds: [Some(2)] }
[2020-03-29T16:21:31Z DEBUG wedding::domain::party::model] Query { sql: "SELECT \"rel_persons_parties\".\"party_id\",  NULL , \"rel_persons_parties\".\"person_id\",  NULL  FROM \"rel_persons_parties\" WHERE \"rel_persons_parties\".\"party_id\" IN ($1)", binds: [Some(74)] }
[2020-03-29T16:21:31Z DEBUG wedding::domain::invitation::model] Query { sql: "SELECT \"invitations\".\"person_id\", \"invitations\".\"id\", \"invitations\".\"rsvp\",  NULL , \"invitations\".\"event_id\" FROM \"invitations\" WHERE \"invitations\".\"person_id\" IN ($1, $2, $3, $4, $5, $6)", binds: [Some(183), Some(184), Some(3), Some(4), Some(1), Some(2)] }
[2020-03-29T16:21:31Z DEBUG wedding::domain::event::model] Query { sql: "SELECT \"rel_events_response_options\".\"event_id\", \"rel_events_response_options\".\"id\",  NULL , \"rel_events_response_options\".\"response_option_id\" FROM \"rel_events_response_options\" WHERE \"rel_events_response_options\".\"event_id\" IN ($1, $2, $3, $4, $5, $6, $7)", binds: [Some(16), Some(10), Some(1), Some(15), Some(14), Some(17), Some(18)] }       
[2020-03-29T16:21:31Z INFO  actix_web::middleware::logger] 127.0.0.1:57245 "POST /graphql HTTP/1.1" 200 12790 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0" 0.675176
[2020-03-29T16:21:41Z ERROR r2d2] server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

[2020-03-29T16:21:41Z DEBUG wundergraph::query_builder::selection] Query { sql: "SELECT \"persons\".\"id\", \"persons\".\"firstname\", \"persons\".\"lastname\", \"persons\".\"gender\", \"persons\".\"side\", \"persons\".\"year_of_birth\", \"persons\".\"address_id\", \"persons\".\"address_id\",  NULL ,  NULL  FROM \"persons\"", binds: [] }
[2020-03-29T16:21:41Z INFO  actix_web::middleware::logger] 127.0.0.1:57216 "POST /graphql HTTP/1.1" 200 37857 "http://localhost:3000/admin/guestlist" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0" 38.547402
[2020-03-29T16:21:49Z ERROR r2d2] server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

[2020-03-29T16:21:49Z DEBUG wundergraph::query_builder::selection] Query { sql: "SELECT \"events\".\"id\", \"events\".\"name\", \"events\".\"description\", \"events\".\"image_url\", \"events\".\"location_url\",  NULL ,  NULL , \"events\".\"start_time\",  NULL ,  NULL ,  NULL , \"events\".\"address_id\" FROM \"events\" WHERE \"events\".\"event_type\" = $1 ORDER BY \"events\".\"start_time\" ASC", binds: [MainEvent] }
[2020-03-29T16:21:50Z INFO  actix_web::middleware::logger] 127.0.0.1:57246 "POST /graphql HTTP/1.1" 200 1178 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0" 19.433219

@weiznich
Copy link
Member

That sounds like something is terminating your connections at network level. r2d2 does issue checks if a connection is active if it pulls a connection from a given pool. Diesel provides a callback to do this, y just sending a SELECT 1; statement, so if that does not work any more the connection is clearly broken. A assume r2d2 then drops the connection and tries to get a new one. If the connection to the server is really done for whatever reason we cannot terminate the connection on server side from the client by calling the corresponding function, as the server is not there any more.

I think I'm closing this issue now, as I do not see anything actionable for the diesel team what could be done to improve this situation. Seems like this is just the behaviour of libpq in such cases.
(That does not mean I won't look in this issue any more)

@andrejohansson
Copy link
Author

I know this is closed but I try to add more potential info as I go along...hope it´s ok. I just found this (a bit old) but maybe a clue? actix/actix-web#24

@weiznich
Copy link
Member

weiznich commented Apr 3, 2020

Sure it's totally fine to comment here with more information. I'm also curious what is causing this, it's just that I do not see what on diesel side could cause this.

@andrejohansson
Copy link
Author

I agree, knowing where the error is a mystery to me too so far.

  • My code
  • Diesel
  • Juniper
  • Actix
  • Something in the container/docker
  • Something in the azure platform
  • Something in postgresql that might be misconfigured?

wedding

I have put up a monitor on the graphql introspection endpoint and I can still see that the app dies for half an hour (!) every now and then.

image

The frequence of crashes was higher before and I fixed that. I was passing the database connection string via environment variables. But it seems that there was some race condition populating the variables in the container.

Either azure did not pass them along on boot, or the container did not pick them up or the rust threads didn´t get them. I removed this source of error by passing along the connection string in a settings file for now.

Still seeing connection flooding though...with the only traffic being the monitor calls that run every 5 minutes (and they should´t even hit the db, only the graphql endpoint).

If you wan´t, I can add you to the project @weiznich to give you a better chance of investigating if you have interest.

@andrejohansson
Copy link
Author

The hunt goes on...I installed pgbouncer in an attempt to not flood the db and get some more logs. And with that info, my latest prime suspect in dealing with the broken connections is r2d2.

@weiznich, do you have (or would you mind making) an example of how to use wundegraph without r2d2 connection pooling?

@weiznich
Copy link
Member

@andrejohansson It should be possible to just use a raw connection instead of a pooled connection as context type in wundergraph out of the box. That said I'm not sure how to handle the integration in a web framework in such cases.

@kgalang
Copy link

kgalang commented Apr 19, 2020

@andrejohansson Hello! I ran into similar issues on my local. I had issues reaching my max amount of connections to my postgres database. My pg_stat_activity view looked the same as yours too where I had all these queries to set the encoding to utf-8.

I would look into how many "workers" you're initializing from your actix-web server. The actix docs says (https://actix.rs/docs/server/):

HttpServer automatically starts a number of http workers, by default this number is equal to number of logical CPUs in the system

So on my local machine, by default, I ran 8 workers on my server and for each worker my connection pool from r2d2 would create 10 connections. And by default, 100 was my max amount of connections on my postgres db. So when I ran my local server and ran my tests in a separate terminal, I'd get weird/inconsistent results because my max connections was reached.

I'm not so familiar with Azure, but since you're on a docker container, would your "number of logical CPUs in the system" ever change? My guess is that if you're running on a system that automatically scales up and down at all, you'd have a decent chance of going over the connection limit. Especially if the error from exceeding the connection limit causes you to spin up another service which would then attempt to create its own connection pools.

Please let me know if this helps or ends up being relevant to your issues!

@andrejohansson
Copy link
Author

andrejohansson commented Apr 19, 2020

Hello!

You are partly right. I have come a bit further on the issue.

I have, as you said a lot of cpu´s on my system (12 logical cores) and I had a pooling setting of 8 which quickly added up to the max_connections limit. This explained to me why it "felt" like the system got choked much faster when I ran locally against the db.

But still...even after tweaking these numbers (setting workers to 1 and pool connections to 2) things didn´t quite work as i expected. Suddenly it just died again.

Turns out that I wasnt´t far of....I remembered that I have had problems with azure before and its load balancer. Note that I am running a VM and then postgres on that vm. I am not using the hosted Postgres service on azure.

Current hypothesis

Sometimes azure does "magic behind the curtains". I suspect this might be such a case. If the connection pool opens up X idle connections against my azure vm running postgres. Then the azure network firewall/balancer cuts those connections silently after roughly 4 minutes (in the default configuration). But for some reason the connection driver on my end does not understand that the connection is gone, and the pool happily serves a dead connection when requested.

Killing the conneciotns while letting both ends still think they are alive and idle is nasty. It would lead to the pool thinking it has 8 healthy connections it can use. But as soon as it picks one and sends a query. Nothing will happen.

Possible alternative workarounds/solutions

  • Add keepalive queries: Somehow send a select 1 query on all connections at intervals smaller than 4 minutes (azure vm connection timeout).
  • Add error handling to reset connections: If a thread panics or a query_wait_timeout is received, then completely reset ALL connections in the pool since they might be dirty.

Topics that may be related

My current solution

Just to test my hypothesis, i launched a small instance on https://www.elephantsql.com/ roughly a week ago and I have had no issue since! So...for me the problem is solved for now.

However, some part is still not right. Is it azures load balancer being dirty? Should something be done to r2d2 to improve detetction of killed connections? To the rust postgres driver?

@andrejohansson
Copy link
Author

@weiznich the above comment might be of interest to you to if you were curious before.
And thank you for your response @kgalang!

@kgalang
Copy link

kgalang commented Apr 19, 2020

@andrejohansson thanks for the details!

I wonder if you had a healthcheck somewhere that somehow keeping a connection to your postgres vm endpoint since it would likely not have the logic in place to close the connection.

For a crate like r2d2 or maybe even a separate crate, I guess you can introduce more automatic management. Like querying connections, seeing which "workers" or clients are connected and how many they have. Then this crate can lower the amount of connections in each client's pool.

For r2d2, I wonder if they may make a "desired connections per pool" config then back off this number as total connections approaches the max connections config. As a user of r2d2, I'd be able to "aim" for a certain amount of connections per pool, say 10. But if we're over 50% of the db's max connections, we only add 7 connections if another pool is needed, then only 3 connections if over 75% or whatever the next threshold. Then you can also give warnings at some point.

Anyways, this got way off topic from diesel but has definitely been an interesting conversation haha

Additional thoughts:
If the above ideas are added to a crate, I can see an issue since this code/logic would be running on every instance of the app/server. But I guess each instance with r2d2/similar crate might be able to infer how many instances there are since it would be querying the database for who's connected and how many times.

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