ソースを参照

Merge pull request #22 from docker/fix-worker-race-condition

Fix race condition in worker
Ben Firshman 9 年 前
コミット
d801ba9838
1 ファイル変更9 行追加1 行削除
  1. 9 1
      worker/src/Worker/Program.cs

+ 9 - 1
worker/src/Worker/Program.cs

@@ -40,17 +40,25 @@ namespace Worker
 
         private static NpgsqlConnection OpenDbConnection(string connectionString)
         {
-            var connection = new NpgsqlConnection(connectionString);
+            NpgsqlConnection connection;
+
             while (true)
             {
                 try
                 {
+                    connection = new NpgsqlConnection(connectionString);
                     connection.Open();
                     break;
                 }
+                catch (SocketException)
+                {
+                    Console.Error.WriteLine("Failed to connect to db - retrying");
+                    Thread.Sleep(1000);
+                }
                 catch (DbException)
                 {
                     Console.Error.WriteLine("Failed to connect to db - retrying");
+                    Thread.Sleep(1000);
                 }
             }