Skip to content

Race condition #5

Description

@Enyium

I only checked the Windows code.

If two processes start at about the same time, process A that doesn't receive ERROR_ALREADY_EXISTS may not yet have written into the mapping, while process B that received ERROR_ALREADY_EXISTS tries to read the mapping, which contains 0 at that point.

It looks like there's no way around using CreateMutexW() (and ReleaseMutex()) as well to synchronize the two processes. You could use the caller-provided name also for CreateMutexW() (but with an at least single-character prefix/suffix to avoid a conflict), which would limit that name to MAX_PATH, minus the length of a possible Local\(/Global\) prefix, minus the length of the mutex differentiation prefix/suffix. Or you could simply use the same fixed version-4 UUID (maybe with crate name prefix/suffix) for all apps and app instances, because process starts are relatively slow anyways and the blocking duration, if happening at all, would be very short.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions