Skip to content

Commit 3eb6a68

Browse files
committed
fix(recording): make named pipe reconnection more resiliant
1 parent 1db86b6 commit 3eb6a68

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

dll/NamedPipe.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,38 @@ HANDLE MsRdpEx_NamedPipe_Open(const char* np_name)
4040

4141
sprintf_s(filename, sizeof(filename) - 1, "\\\\.\\pipe\\%s", np_name);
4242

43-
np_handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
44-
45-
if (np_handle == INVALID_HANDLE_VALUE) {
46-
return NULL;
43+
for (int attempt = 0; attempt < 10; ++attempt)
44+
{
45+
np_handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
46+
47+
if (np_handle != INVALID_HANDLE_VALUE)
48+
{
49+
return np_handle;
50+
}
51+
52+
DWORD err = GetLastError();
53+
54+
if (err == ERROR_PIPE_BUSY)
55+
{
56+
MsRdpEx_LogPrint(DEBUG, "named pipe '%s' is busy, wait and retry", np_name);
57+
58+
if (!WaitNamedPipeA(filename, 25))
59+
{
60+
Sleep(75);
61+
}
62+
}
63+
else if (err == ERROR_FILE_NOT_FOUND)
64+
{
65+
MsRdpEx_LogPrint(DEBUG, "named pipe '%s' not found, wait and retry", np_name);
66+
67+
Sleep(100);
68+
continue;
69+
}
70+
else
71+
{
72+
MsRdpEx_LogPrint(WARN, "failed to open named pipe '%s' (%lu)", np_name, errno);
73+
break;
74+
}
4775
}
4876

4977
return np_handle;

0 commit comments

Comments
 (0)