Skip to content

Commit d801ba9

Browse files
authored
Merge pull request dockersamples#22 from docker/fix-worker-race-condition
Fix race condition in worker
2 parents dea83e7 + c57e9c3 commit d801ba9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

worker/src/Worker/Program.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,25 @@ public static int Main(string[] args)
4040

4141
private static NpgsqlConnection OpenDbConnection(string connectionString)
4242
{
43-
var connection = new NpgsqlConnection(connectionString);
43+
NpgsqlConnection connection;
44+
4445
while (true)
4546
{
4647
try
4748
{
49+
connection = new NpgsqlConnection(connectionString);
4850
connection.Open();
4951
break;
5052
}
53+
catch (SocketException)
54+
{
55+
Console.Error.WriteLine("Failed to connect to db - retrying");
56+
Thread.Sleep(1000);
57+
}
5158
catch (DbException)
5259
{
5360
Console.Error.WriteLine("Failed to connect to db - retrying");
61+
Thread.Sleep(1000);
5462
}
5563
}
5664

0 commit comments

Comments
 (0)