Does RDS Proxy support long-lived connections?

0

Hi,

I have a problem with long-lived connections and RDS Proxy, does RDS proxy a connection that live more than 24 hours? I have found out that every 24 hours all connections from my client to the proxy are terminated by the proxy.

According to the documentation: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy-managing.html -> MaxIdleConnectionsPercent

RDS Proxy considers a database connection in it's pool to be idle when there's been no activity on the connection for five minutes.

RDS Proxy closes database connections some time after 24 hours when they are no longer in use. The proxy performs this action regardless of the value of the maximum idle connections setting.

So to keep a connection alive I thought that could be enough to "ping" the database with a "SELECT 1" with a frequency < 5 minutes but I made several tests with my java app and every time the proxy close the connection after 24 hours.

To reproduce the problem I have wrote a minimal PHP script:

<?php

ini_set('error_reporting', '1');
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
ini_set('memory_limit', '256M');
ini_set('max_execution_time', '0');


$hostname = 'host';
$username = 'user';
$password = 'pass';
$database = 'db';

$conn = mysqli_connect($hostname, $username, $password, $database);

if (!$conn) {
	die("Error on connection: " . mysqli_connect_error());
}

while (1) {

	$query = "SELECT 1";
	$result = mysqli_query($conn, $query);

	if ($result) {
		echo date("Y-m-d H:i:s") . ': SELECT 1' . "\n";
	} else {
		echo "Error: " . mysqli_error($conn) . "\n";
		exit;
	}

	sleep(120);
}

The output is:

$ php -q test.php
2023-09-03 07:49:52: SELECT 1
2023-09-03 07:51:52: SELECT 1
2023-09-03 07:53:52: SELECT 1
.....
.....
2023-09-04 07:45:53: SELECT 1
2023-09-04 07:47:53: SELECT 1
2023-09-04 07:49:53: SELECT 1
Error: MySQL server has gone away

exactly after 24 hours I the connection is dropped and on the logs of the proxy I get:

2023-09-04T07:50:05.001Z [INFO] [proxyEndpoint=default] [clientConnection=1192216169] The client connection closed. Reason: The connection exceeded the maximum connection duration.

So does RDS proxy support long-lived connection? I haven't read anywhere in the doc that are not supported, instead here: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy-planning.html

the doc says:

Applications that keep a large number of connections open for long periods are typically good candidates for using a proxy.

why ALL the connections are dropped after 24 also if they are NOT idle? I had the same problem also on connections that are running a period task that are not simple 'SELECT 1'

regards

2 Answers
0

Response from the support

I would like to mention that the rds proxy connection get closed after 24 hours is expected behavior. RDS Proxy won't close connection when there is ongoing transaction. But once the transaction is completed and the database connection age has passed 24 hours, it will be added to the termination queue.

Soon it will be closed again where its not within a transaction. When 24 hrs time is reached, the proxy checks if the client connection is in transaction. If so, the proxy waits at most 15 more mins. If after 15 mins the client connections is still in transaction, then proxy would drop the client connection regardless." .This is expected behavior due to architectural design which is similar in Aurora serverless.

"Aurora Serverless v1 closes connections that are older than 24 hours." [+] https://aws.amazon.com/blogs/database/best-practices-for-working-with-amazon-aurora-serverless/

As you are looking for more clarification about the below in the documentation above mentioned is not updated in our public documentation, but will be updated soon. As this is required to undergo a change process, I am not in a position to provide the ETA on when the document will be updated.

TL;DR: the doc is not clear, we will fix it

answered 8 months ago
-1

Hi, Can you explain in a comment to my question why it is important for your use case to maintain connection open for such a long time? Why is a reconnection an issue in this use case?

Best,

Didier

profile pictureAWS
EXPERT
answered 8 months ago
  • Our infrastructure is based on Java microservices, each microservice is an independent processes without an application servers, messages are passed through queues. I need that connection remain always active, any process that remains active for an extended period has the same requirement; it doesn't seem like an isolated use case to me

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions