Skip to content

Commit

Permalink
Fixed bug CORE-3325 : At high load it is possible that new process co…
Browse files Browse the repository at this point in the history
…uld fail to map shared memory
  • Loading branch information
hvlad committed Feb 2, 2011
1 parent a3302e4 commit 0c73f2c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/common/isc_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,16 @@ bool SharedMemoryBase::mapFile(Arg::StatusVector& statusVector,
return false;
}

if (!init_flag)
{
if ((GetLastError() != ERROR_ALREADY_EXISTS) || SetFilePointer(file_handle, 0, NULL, FILE_END) == 0)

This comment has been minimized.

Copy link
@mikekaganski

mikekaganski Aug 30, 2021

Zero seems a normal value for SetFilePointer[1] - just telling that the file is yet empty; is it really correct here, and isn't INVALID_SET_FILE_POINTER meant here?

It fails for me locally in LibreOffice - having the empty file and looping infinitely.

1

This comment has been minimized.

Copy link
@mikekaganski

mikekaganski Aug 30, 2021

Created #6937

{
CloseHandle(event_handle);
CloseHandle(file_handle);
goto retry;
}
}

// Create a file mapping object that will be used to make remapping possible.
// The current length of real mapped file and its name are saved in it.

Expand Down Expand Up @@ -2210,10 +2220,17 @@ bool SharedMemoryBase::mapFile(Arg::StatusVector& statusVector,
if (init_flag)
{
FlushViewOfFile(address, 0);
SetEvent(event_handle);

DWORD err = 0;
if (SetFilePointer(sh_mem_handle, length, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER ||
!SetEndOfFile(sh_mem_handle) ||
!FlushViewOfFile(address, 0))
{
err = GetLastError();
}

SetEvent(event_handle);
if (err)
{
error(statusVector, "SetFilePointer", GetLastError());
return false;
Expand Down

0 comments on commit 0c73f2c

Please sign in to comment.