Skip to contentSkip to conversation

tests/libqtest.c: Delete possible stale unix sockets

PATCH In review Peter Maydell 5 participants 6 messages Mar 31, 2017 – Apr 11, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/libqtest.c: Delete possible stale unix sockets

Occasionally if a test crashes or is interrupted by the user at the wrong moment it could leave behind a stale UNIX
socket in /tmp/. This will then cause a subsequent test
run to fail spuriously with
tests/libqtest.c:70:init_socket: assertion failed (ret != -1): (-1 != -1)
if it happens to reuse the same PID.

Defend against this by deleting any stray stale socket before trying to open the new ones for this test.

---
This seems like an easy way to shut up this infrequent but irritating error case...

 tests/libqtest.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tests/libqtest.c +8 -0
index a5c3d2b..99b1195 100644
@@ -167,6 +167,14 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
     qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
 
+    /* It's possible that if an earlier test run crashed it might
+     * have left a stale unix socket lying around. Delete any
+     * stale old socket to avoid spurious test failures with
+     * tests/libqtest.c:70:init_socket: assertion failed (ret != -1): (-1 != -1)
+     */
+    unlink(socket_path);
+    unlink(qmp_socket_path);
+
     sock = init_socket(socket_path);
     qmpsock = init_socket(qmp_socket_path);
 
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Peter Maydell

Occasionally if a test crashes or is interrupted by the user at the wrong moment it could leave behind a stale UNIX
socket in /tmp/. This will then cause a subsequent test
run to fail spuriously with
tests/libqtest.c:70:init_socket: assertion failed (ret != -1): (-1 != -1)
if it happens to reuse the same PID.

Defend against this by deleting any stray stale socket before trying to open the new ones for this test.

Quoted 27 lines

---
This seems like an easy way to shut up this infrequent but irritating error case...

 tests/libqtest.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tests/libqtest.c +8 -0
index a5c3d2b..99b1195 100644
@@ -167,6 +167,14 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
     qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
 
+    /* It's possible that if an earlier test run crashed it might
+     * have left a stale unix socket lying around. Delete any
+     * stale old socket to avoid spurious test failures with
+     * tests/libqtest.c:70:init_socket: assertion failed (ret != -1): (-1 != -1)
+     */
+    unlink(socket_path);
+    unlink(qmp_socket_path);
+
     sock = init_socket(socket_path);
     qmpsock = init_socket(qmp_socket_path);
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Maydell
Quoted 7 lines · Peter Maydell

Occasionally if a test crashes or is interrupted by the user at the wrong moment it could leave behind a stale UNIX
socket in /tmp/. This will then cause a subsequent test
run to fail spuriously with
tests/libqtest.c:70:init_socket: assertion failed (ret != -1): (-1 != -1)
if it happens to reuse the same PID.

Quoted 7 lines

Defend against this by deleting any stray stale socket before trying to open the new ones for this test.

---
This seems like an easy way to shut up this infrequent but irritating error case...

There is a related failure in qemu-iotests that I hit yesterday:

+mkfifo: cannot create fifo '/home/eblake/qemu/tests/qemu-iotests/scratch/qmp-out-3812_0': File exists

that is probably also worth addressing, but that can be a separate patch.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 1/1
#3 lore raw
In reply to Peter Maydell
Quoted 10 lines · Peter Maydell

Occasionally if a test crashes or is interrupted by the user at the wrong moment it could leave behind a stale UNIX
socket in /tmp/. This will then cause a subsequent test
run to fail spuriously with
tests/libqtest.c:70:init_socket: assertion failed (ret != -1): (-1 != -1)
if it happens to reuse the same PID.

Defend against this by deleting any stray stale socket before trying to open the new ones for this test.

Quoted 7 lines

---
This seems like an easy way to shut up this infrequent but irritating error case...

 tests/libqtest.c | 8 ++++++++
 1 file changed, 8 insertions(+)
#4 lore raw
In reply to Peter Maydell
Quoted 26 lines · Peter Maydell

Occasionally if a test crashes or is interrupted by the user at the wrong moment it could leave behind a stale UNIX
socket in /tmp/. This will then cause a subsequent test
run to fail spuriously with
tests/libqtest.c:70:init_socket: assertion failed (ret != -1): (-1 != -1)
if it happens to reuse the same PID.

Defend against this by deleting any stray stale socket before trying to open the new ones for this test.

---
This seems like an easy way to shut up this infrequent but irritating error case...

 tests/libqtest.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tests/libqtest.c +0 -0
index a5c3d2b..99b1195 100644
@@ -167,6 +167,14 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
     qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
 

tests/libqtest.c QTestState *qtest_init_without_qmp_handshake(const char *extra_args) · line 179

Quoted 10 lines
tests/libqtest.c +8 -0
+    /* It's possible that if an earlier test run crashed it might
+     * have left a stale unix socket lying around. Delete any
+     * stale old socket to avoid spurious test failures with
+     * tests/libqtest.c:70:init_socket: assertion failed (ret != -1): (-1 != -1)
+     */
+    unlink(socket_path);
+    unlink(qmp_socket_path);
+
     sock = init_socket(socket_path);
     qmpsock = init_socket(qmp_socket_path);

No objection to this work-around for tests leaving crap behind, but I think we should also try harder not to leave crap behind. Say give each test its own scratch directory, make sure no test writes outside it, and have the harness remove it afterwards.

#5 lore raw
Quoted 4 lines · Markus Armbruster

No objection to this work-around for tests leaving crap behind, but I think we should also try harder not to leave crap behind. Say give each test its own scratch directory, make sure no test writes outside it, and have the harness remove it afterwards.

That would all be nice, yes :-)

thanks
-- PMM