类 Unix 单实例锁不生效

Open
#3,868 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp
Domain
desktop-dev

Research direction

The bug is in PCL.Core/App/Essentials/SingleInstanceService.cs around lines 136-140, where the lock file is opened with FileShare.Read, which on Unix only takes a shared flock and lets a second process write its PID. Start by reading that method and confirming how the file is opened and when the PID is written. Done means a second instance is refused on Linux and macOS while Windows behaviour is unchanged, verified by launching two copies.

Written by the indexing model from the issue text.

Description

https://github.com/PCL-Community/PCL-CE/blob/fdf5e5530b8b5becc4227f9d588235bfd0f5045a/PCL.Core/App/Essentials/SingleInstanceService.cs#L136-L140

Windows 上 FileShare.Read 会阻止第二个写句柄。类 Unix 上 .NET 对非 FileShare.None 的共享模式只加共享 flock,第二个进程仍能读写同一文件并写入自己的 PID。

考虑使用真正的进程间锁,FileShare.None 配合 FileStream.Lock 与 flock,或类 Unix 命名 Mutex。

Dominant language
C#
Stars
4.3k
Forks
148
Avg merge
1d 6h
Merged PRs (30d)
64

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PCL-Community/PCL-CE

All issues in PCL-Community/PCL-CE

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.