Skip to content

feat(instance): run one copy per session - #18

Merged
mrcsin merged 9 commits into
masterfrom
single-instance
Nov 7, 2026
Merged

mrcsin merged 9 commits into
masterfrom
single-instance

Conversation

@mrcsin

@mrcsin mrcsin commented Nov 7, 2026

Copy link
Copy Markdown
Member

A second launch started a second copy that competed for the COM port and the history file. Now only one copy runs per Windows session.

  • The first copy holds a named lock. A second launch signals it; the first copy restores its window if minimised, brings it to the front and answers, and the second launch exits without opening a window, the port or the history file.
  • Without an answer the second launch frees the name and claims it again every 2 s: if the old copy is gone (closing, or killed) it continues as the running copy. After 10 s it shows «SemiSpec уже запущена, но не отвечает…» with every handle already closed, so killing the hung copy and starting again works while the message is still open.
  • The running copy releases the lock as soon as its window starts closing, so a relaunch during the close opens a new window; the new copy retries a port and a history file that the old copy still holds (the store open retries a busy file for up to 6 s and never sets it aside).
  • A lock Windows refuses runs the copy as the only one, with one Warning.

Verified: 1067 tests (1045 before), the instance tests 5 runs in a row, Release build 0 warnings, format and terse clean. Reviewed by a second model; the fixes for its findings are in the last three commits. Left for the operator PC: the 7 manual checks in the plan (window to the front, three launches, hung copy, close and relaunch, cold start after reboot).

🤖 Generated with Claude Code

mrcsin and others added 9 commits November 7, 2026 09:26
A second launch starts a second copy that competes for the COM port
and the history file. The plan lets only one copy run: a second launch
brings the open window to the front and exits, or says the first copy
is not responding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second SemiSpec copy would open the same COM port and the same history
file, which takes one writer. SingleInstance claims a Local\ named mutex;
createdNew decides primary or secondary, and the OS frees the name when
the last handle closes, also after a crash. Two auto-reset named events
carry the ask and the answer: the primary answers only after its UI
scheduler ran the activation, and the secondary resets the answer before
it asks, so a late answer cannot count. Release unregisters the wait and
closes every handle, so a launch during a close claims the name anew.
Program and App wire it in the next tasks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second launch of SemiSpec still built the container and opened a
window, a port and a store next to the running copy.

Program.Main now claims the single-instance name right after the logger
exists. A secondary allows the foreground hand-over, asks the running
copy to activate its window, retries once, and exits before "SemiSpec
starting". With no answer it logs one warning, shows the
SingleInstanceNotResponding text in a MessageBoxW box and exits with 1.
The three user32 calls live in NativeMethods as DllImport declarations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A running copy had a claim but nothing listened for a second launch,
and the claim lived until the process exited, so a relaunch during the
close would activate a window about to vanish.

App.Run now takes the claim and starts Listen in AfterSetup, where the
UI dispatcher exists; each ask restores a minimised main window through
ShowWindow and activates it. The first accepted Closing releases the
claim before the stop chain starts, so a launch from then on starts a
new copy. Configure carries the claim, so headless tests cover the
release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A claim the OS refuses had no test; an event holding the mutex name now
shows it runs as primary with one Warning. The plan records the acceptance
results: 1062 of 1062 tests pass, 17 in Area Instance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docs still allowed a second running copy and said two copies share
the history file. They now describe the claim, the second launch, the
listener and the release at the close, the new text key and the
Instance test area.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A secondary kept its mutex and events open while the not-responding box
was up. The claim is handle existence, so killing the hung copy and
starting again, as the message says, met a held name and failed again.
A launch that got no answer also gave up after two asks, too soon for a
cold start of the first copy.

SecondLaunch.Run now closes its handles after every unanswered ask and
claims the name again: a free name lets it continue as the primary, a
held one gets another ask, for up to 10 s. The message shows only after
that budget, with every handle closed. The tests no longer drive a
TestScheduler from two threads, and the close test starts the listener
as the app does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A copy started while the previous copy closes meets a history file that
copy still holds for up to its 5 s close limit. The open failed with
SQLITE_BUSY and the store stayed off for the whole run.

StoreOpening retries an open that fails with SQLITE_BUSY or SQLITE_LOCKED
every 0.5 s for 6 s from the start of the open, then fails as before. A
held file is never set aside or deleted. The stop's drain token ends the
retries early.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docs described one retry, a message after about 4 s and a store
open that fails on a held file. They now describe the re-claim rounds,
the 10 s budget, the handles closed before the message, the busy-open
retry and why the claim is released before the stop. The plan marks
the smoke steps as not run and adds a cold-start step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mrcsin
mrcsin merged commit 6ed7de2 into master Nov 7, 2026
1 check passed
@mrcsin
mrcsin deleted the single-instance branch November 7, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant