From ceed50e8b1d8a7f560a99477f4a0caf0bc111a04 Mon Sep 17 00:00:00 2001 From: Manoj Ampalam Date: Wed, 18 Jan 2017 22:09:47 -0800 Subject: [PATCH] Fixed issue:key based auth ocassionally fails (https://github.com/PowerShell/Win32-OpenSSH/issues/481) --- authfd.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/authfd.c b/authfd.c index b6ec0ffcd..6d275454a 100644 --- a/authfd.c +++ b/authfd.c @@ -108,10 +108,18 @@ ssh_get_authentication_socket(int *fdp) RegCloseKey(agent_root); } - h = CreateFileW(SSH_AGENT_PIPE_NAME, GENERIC_READ | GENERIC_WRITE, 0, - NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); - if (h == INVALID_HANDLE_VALUE) + do { + h = CreateFileW(SSH_AGENT_PIPE_NAME, GENERIC_READ | GENERIC_WRITE, 0, + NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + if (h != INVALID_HANDLE_VALUE || GetLastError() != ERROR_PIPE_BUSY) + break; + Sleep(100); + } while(1); + + if (h == INVALID_HANDLE_VALUE) { + debug("ssh_get_authentication_socket - CreateFileW failed error %d", GetLastError()); return SSH_ERR_AGENT_NOT_PRESENT; + } /* * ensure that connected server pid matches published pid. this provides service side