Skip to content

Commit 0c73f2c

Browse files
committed
Fixed bug CORE-3325 : At high load it is possible that new process could fail to map shared memory
1 parent a3302e4 commit 0c73f2c

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/common/isc_sync.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,16 @@ bool SharedMemoryBase::mapFile(Arg::StatusVector& statusVector,
20892089
return false;
20902090
}
20912091

2092+
if (!init_flag)
2093+
{
2094+
if ((GetLastError() != ERROR_ALREADY_EXISTS) || SetFilePointer(file_handle, 0, NULL, FILE_END) == 0)
2095+
{
2096+
CloseHandle(event_handle);
2097+
CloseHandle(file_handle);
2098+
goto retry;
2099+
}
2100+
}
2101+
20922102
// Create a file mapping object that will be used to make remapping possible.
20932103
// The current length of real mapped file and its name are saved in it.
20942104

@@ -2210,10 +2220,17 @@ bool SharedMemoryBase::mapFile(Arg::StatusVector& statusVector,
22102220
if (init_flag)
22112221
{
22122222
FlushViewOfFile(address, 0);
2213-
SetEvent(event_handle);
2223+
2224+
DWORD err = 0;
22142225
if (SetFilePointer(sh_mem_handle, length, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER ||
22152226
!SetEndOfFile(sh_mem_handle) ||
22162227
!FlushViewOfFile(address, 0))
2228+
{
2229+
err = GetLastError();
2230+
}
2231+
2232+
SetEvent(event_handle);
2233+
if (err)
22172234
{
22182235
error(statusVector, "SetFilePointer", GetLastError());
22192236
return false;

0 commit comments

Comments
 (0)