Merge pull request #22 from docker/fix-worker-race-condition
Fix race condition in worker
This commit is contained in:
commit
d801ba9838
@ -40,17 +40,25 @@ namespace Worker
|
|||||||
|
|
||||||
private static NpgsqlConnection OpenDbConnection(string connectionString)
|
private static NpgsqlConnection OpenDbConnection(string connectionString)
|
||||||
{
|
{
|
||||||
var connection = new NpgsqlConnection(connectionString);
|
NpgsqlConnection connection;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
connection = new NpgsqlConnection(connectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
catch (SocketException)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine("Failed to connect to db - retrying");
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
catch (DbException)
|
catch (DbException)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("Failed to connect to db - retrying");
|
Console.Error.WriteLine("Failed to connect to db - retrying");
|
||||||
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user