|
59 | 59 | #include "../common/StatusArg.h" |
60 | 60 | #include "../common/TimeZoneUtil.h" |
61 | 61 | #include "../common/config/config.h" |
| 62 | +#include "../common/ThreadStart.h" |
62 | 63 |
|
63 | 64 | #ifdef WIN_NT |
64 | 65 | #include <direct.h> |
@@ -667,28 +668,41 @@ class PrivateNamespace |
667 | 668 | if (!AddSIDToBoundaryDescriptor(&hBoundaryDesc, &sid)) |
668 | 669 | raiseError("AddSIDToBoundaryDescriptor"); |
669 | 670 |
|
670 | | - m_hNamespace = CreatePrivateNamespace(&sa, hBoundaryDesc, sPrivateNameSpace); |
671 | | - |
672 | | - if (m_hNamespace == NULL) |
| 671 | + int retry = 0; |
| 672 | + while (true) |
673 | 673 | { |
674 | | - DWORD err = GetLastError(); |
675 | | - if (err != ERROR_ALREADY_EXISTS) |
676 | | - raiseError("CreatePrivateNamespace"); |
| 674 | + m_hNamespace = CreatePrivateNamespace(&sa, hBoundaryDesc, sPrivateNameSpace); |
677 | 675 |
|
678 | | - m_hNamespace = OpenPrivateNamespace(hBoundaryDesc, sPrivateNameSpace); |
679 | 676 | if (m_hNamespace == NULL) |
680 | 677 | { |
681 | | - err = GetLastError(); |
682 | | - if (err != ERROR_DUP_NAME) |
683 | | - raiseError("OpenPrivateNamespace"); |
684 | | - |
685 | | - Firebird::string name(sPrivateNameSpace); |
686 | | - name.append("\\test"); |
| 678 | + DWORD err = GetLastError(); |
| 679 | + if (err != ERROR_ALREADY_EXISTS) |
| 680 | + raiseError("CreatePrivateNamespace"); |
687 | 681 |
|
688 | | - m_hTestEvent = CreateEvent(ISC_get_security_desc(), TRUE, TRUE, name.c_str()); |
689 | | - if (m_hTestEvent == NULL) |
690 | | - raiseError("CreateEvent"); |
| 682 | + m_hNamespace = OpenPrivateNamespace(hBoundaryDesc, sPrivateNameSpace); |
| 683 | + if (m_hNamespace == NULL) |
| 684 | + { |
| 685 | + err = GetLastError(); |
| 686 | + if ((err == ERROR_PATH_NOT_FOUND) && (retry++ < 100)) |
| 687 | + { |
| 688 | + // Namespace was closed by its last holder, wait a bit and try again |
| 689 | + Thread::sleep(10); |
| 690 | + continue; |
| 691 | + } |
| 692 | + |
| 693 | + if (err != ERROR_DUP_NAME) |
| 694 | + raiseError("OpenPrivateNamespace"); |
| 695 | + |
| 696 | + Firebird::string name(sPrivateNameSpace); |
| 697 | + name.append("\\test"); |
| 698 | + |
| 699 | + m_hTestEvent = CreateEvent(ISC_get_security_desc(), TRUE, TRUE, name.c_str()); |
| 700 | + if (m_hTestEvent == NULL) |
| 701 | + raiseError("CreateEvent"); |
| 702 | + } |
691 | 703 | } |
| 704 | + |
| 705 | + break; |
692 | 706 | } |
693 | 707 | } |
694 | 708 |
|
|
0 commit comments