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

Сonnection pool has been exhausted when database is down #2616

Closed
alex-namely opened this issue Sep 11, 2019 · 1 comment · Fixed by #2622

Comments

@alex-namely
Copy link

commented Sep 11, 2019

Hello,
In production we have been using the latest stable version 4.0.10.
We noticed that in case of database outage we almost immediately are spammed with The connection pool has been exhausted exceptions.

In my test console app I set pool size = 2 and threads number = 5 also I intentionally left database in offline mode.

var tasks = new List<Task>();
for (var i = 1; i <= 5; i++)
{
	tasks.Add(Task.Run(async () =>
	{
		try
		{
			using (var conn = new NpgsqlConnection(connectionString))
			{
				await conn.OpenAsync();
			}
		}
		catch (NpgsqlException e) when (e.Message.Contains("Exception while connecting"))
		{
			Console.WriteLine($"1. thread id: {Thread.CurrentThread.ManagedThreadId:0000} message: {e.Message}");
		}
		catch (NpgsqlException e) when (e.Message.Contains("The connection pool has been exhausted"))
		{
			Console.WriteLine($"2. thread id: {Thread.CurrentThread.ManagedThreadId:0000} message: {e.Message}");
		}
	}
	));
}
Task.WaitAll(tasks.ToArray());

In 4.1.0-preview2 here is result: connection pool became full

1. thread id: 0017 message: Exception while connecting
1. thread id: 0016 message: Exception while connecting
2. thread id: 0003 message: The connection pool has been exhausted, either raise MaxPoolSize (currently 2) or Timeout (currently 15 seconds)
2. thread id: 0007 message: The connection pool has been exhausted, either raise MaxPoolSize (currently 2) or Timeout (currently 15 seconds)
2. thread id: 0004 message: The connection pool has been exhausted, either raise MaxPoolSize (currently 2) or Timeout (currently 15 seconds)

Similar result is in 4.0.10 with larger threads number (instead of Exception while connecting exceptions there are ExtendedSocketException).

I would expect to see Exception while connecting rather than The connection pool has been exhausted when database is down and there was even no chance for a client to open a connection.

What do you think?

Further technical details

Npgsql version: 4.0.10/4.1.0-preview2
PostgreSQL version: 9.6
.NET Core 2.2

@roji roji added the bug label Sep 11, 2019

@roji roji added this to the 4.0.10 milestone Sep 11, 2019

@roji

This comment has been minimized.

Copy link
Member

commented Sep 11, 2019

@NinoFloris you may be interested in this.

@YohDeadfall YohDeadfall modified the milestones: 4.0.10, 4.1 Sep 12, 2019

roji added a commit that referenced this issue Sep 16, 2019

@roji roji closed this in #2622 Sep 18, 2019

roji added a commit that referenced this issue Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.