Attempt ping from front- to back-end several times (#1990). v2.15.145
authorCarl Hetherington <cth@carlh.net>
Sun, 9 May 2021 14:43:24 +0000 (16:43 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 9 May 2021 21:15:05 +0000 (23:15 +0200)
On macOS it seems that the backend sometimes is not started very
quickly.  Adding a long timeout to ping does not work, perhaps
because the backend is not listening.

Trying a few times seems to fix it.

With this fix I saw this log:

Sun May  9 23:02:51 2021: dcpomatic_disk_writer e63a485e23 started
Sun May  9 23:02:51 2021: Entering main loop
Sun May  9 23:02:51 2021: Writer receives command: P

from the backend and

Sun May  9 23:02:45 2021: Could not send ping to writer (attempt 1)
Sun May  9 23:02:47 2021: Could not send ping to writer (attempt 2)
Sun May  9 23:02:49 2021: Could not send ping to writer (attempt 3)

from the front-end, suggesting that the first 3 pings went to /dev/null
and the 4th was heard.

src/tools/dcpomatic_disk.cc

index 0a53a0a9bd02f8ec390267cec1f8c98930ec4958..3daffb72d0b94d7d8b0c1b340f4d1359bcaa2c3f 100644 (file)
@@ -249,18 +249,27 @@ private:
                DCPOMATIC_ASSERT (_drive->GetSelection() != wxNOT_FOUND);
                DCPOMATIC_ASSERT (static_cast<bool>(_dcp_path));
 
-               bool have_writer = true;
-               if (!_nanomsg.send(DISK_WRITER_PING "\n", 2000)) {
-                       LOG_DISK_NC("Could not send ping to writer");
-                       have_writer = false;
-               } else {
-                       auto reply = _nanomsg.receive (2000);
-                       if (!reply) {
-                               LOG_DISK_NC("No reply received from ping");
-                               have_writer = false;
-                       } else if (*reply != DISK_WRITER_PONG) {
-                               LOG_DISK_NC("Unexpected response to ping received");
-                               have_writer = false;
+               auto ping = [this](int attempt) {
+                       if (_nanomsg.send(DISK_WRITER_PING "\n", 2000)) {
+                               auto reply = _nanomsg.receive (2000);
+                               if (reply && *reply == DISK_WRITER_PONG) {
+                                       return true;
+                               } else if (reply) {
+                                       LOG_DISK("Unexpected response %1 to ping received (attempt %2)", *reply, attempt);
+                               } else {
+                                       LOG_DISK("No reply received from ping (attempt %1)", attempt);
+                               }
+                       } else {
+                               LOG_DISK("Could not send ping to writer (attempt %1)", attempt);
+                       }
+                       return false;
+               };
+
+               bool have_writer = false;
+               for (int i = 0; i < 8; ++i) {
+                       if (ping(i + 1)) {
+                               have_writer = true;
+                               break;
                        }
                }