Skip to content

fix: don't kill the primary instance on large second-instance messages - #52628

Merged
VerteDinde merged 1 commit into
mainfrom
fix-singleton-large-messages
Aug 18, 2026
Merged

VerteDinde merged 1 commit into
mainfrom
fix-singleton-large-messages

Conversation

@VerteDinde

Copy link
Copy Markdown
Member

Description of Change

The POSIX process singleton read a second instance's notification message into a fixed 32 KiB buffer, and the sending side gave up as soon as write() would block on its non-blocking socket. A command line or additionalData payload beyond those limits was therefore either silently truncated or, when the write couldn't complete, made the second instance SIGKILL the primary process as "unresponsive."

This extends the existing additionalData patch so the primary reads the message into a growable buffer until the client shuts down its end of the socket, and the client waits for the socket to become writable instead of bailing out. Adds specs covering a large additionalData payload and a long command-line argument.

Checklist

Release Notes

Notes: Fixed the primary instance being killed or receiving truncated arguments when a second instance passed a very long command line or large additionalData to app.requestSingleInstanceLock().

@VerteDinde VerteDinde added semver/patch backwards-compatible bug fixes target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. labels Aug 3, 2026
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Aug 3, 2026
@VerteDinde
VerteDinde marked this pull request as ready for review August 3, 2026 23:30
@VerteDinde
VerteDinde requested a review from a team as a code owner August 3, 2026 23:30
@VerteDinde
VerteDinde enabled auto-merge (squash) August 4, 2026 03:41
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Aug 4, 2026

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM other than we should document the new limit in our docs.
Some additional feedback from AI review:
Non-blocking socket relies on a DCHECK (pre-existing, but worth fixing here): Upstream makes the accepted fd non-blocking via DCHECK(base::SetNonBlocking(connection_socket)), which doesn't execute when DCHECKs are compiled out — so in release builds the fd stays blocking. This hazard predates this PR (the old ReadFromSocketWithTimeout loop could also block on a stalled client), but the new read loop depends on EAGAIN for its "wait for the rest of the message" path, which never triggers on a blocking fd — instead the IO thread sits in read() until EOF, and the cleanup timer_ (same thread) can't fire. Suggest adding a hunk to set non-blocking unconditionally, e.g. if (!base::SetNonBlocking(connection_socket)) PLOG(ERROR) << ....

Oversized messages are silently swallowed: >32 MiB gets drained, ACK'd, and dropped — second-instance never fires and the second instance exits as if handled, with only a LOG(ERROR). Reasonable fallback, but docs/api/app.md (requestSingleInstanceLock / additionalData) should mention the 32 MiB cap and drop behavior.

Write timeout is per-blocked-write, not overall: with SO_SNDTIMEO also set to timeout, a hung primary costs ~2× timeout before giving up, and a slow-but-alive reader can extend the total well past timeout. Probably intended — a comment clarifying the bound is per-block would help.

Nits: WaitSocketForWrite inherits the select()/FD_SETSIZE UB pattern from WaitSocketForRead (fine for consistency; poll() would be safer). The 4 KiB chunk means ~8k read() syscalls for a max-size message — 64 KiB would be a free win. Comment grammar: "Wait a socket for write" → "Wait for a socket to become writable".

@MarshallOfSound

Copy link
Copy Markdown
Member

Heads up: Windows CI builds moved to new runners on Monday and the old ones have now been removed. This branch predates that, so its Windows build jobs still point at the old runners and will sit queued forever if CI runs again. Rebasing on main (or "Update branch") picks up the change, nothing else needed.

The POSIX process singleton read a second instance's notification into
a fixed 32 KiB buffer and gave up as soon as writing to the socket would
block. Command lines or additionalData payloads beyond those limits
were either silently truncated or, when the write couldn't complete,
made the second instance kill the primary process as unresponsive.
@VerteDinde
VerteDinde force-pushed the fix-singleton-large-messages branch from efd445e to aa05298 Compare August 17, 2026 05:57
@VerteDinde
VerteDinde dismissed jkleinsc’s stale review August 17, 2026 06:00

Changes addressed and documentation added

@VerteDinde
VerteDinde requested a review from jkleinsc August 17, 2026 06:00
@VerteDinde
VerteDinde merged commit 1652d8e into main Aug 18, 2026
197 of 202 checks passed
@VerteDinde
VerteDinde deleted the fix-singleton-large-messages branch August 18, 2026 06:22
@release-clerk

release-clerk Bot commented Aug 18, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed the primary instance being killed or receiving truncated arguments when a second instance passed a very long command line or large additionalData to app.requestSingleInstanceLock().

@trop

trop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "41-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot removed the target/41-x-y PR should also be added to the "41-x-y" branch. label Aug 18, 2026
@trop

trop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "43-x-y" cleanly;
you will need to perform this backport manually.

@trop

trop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "42-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot added needs-manual-bp/43-x-y and removed target/43-x-y PR should also be added to the "43-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Aug 18, 2026
@trop

trop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #52950

@trop trop Bot added in-flight/44-x-y merged/44-x-y PR was merged to the "44-x-y" branch. and removed target/44-x-y PR should also be added to the "44-x-y" branch. in-flight/44-x-y labels Aug 18, 2026
@trop

trop Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

@VerteDinde has manually backported this PR to "43-x-y", please check out #53156

@trop

trop Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

@VerteDinde has manually backported this PR to "42-x-y", please check out #53157

MarshallOfSound pushed a commit that referenced this pull request Aug 25, 2026
#53157)

fix: don't kill the primary instance on large second-instance messages (#52628)

The POSIX process singleton read a second instance's notification into
a fixed 32 KiB buffer and gave up as soon as writing to the socket would
block. Command lines or additionalData payloads beyond those limits
were either silently truncated or, when the write couldn't complete,
made the second instance kill the primary process as unresponsive.

(cherry picked from commit 1652d8e)
@trop trop Bot added merged/42-x-y PR was merged to the "42-x-y" branch. and removed in-flight/42-x-y labels Aug 25, 2026
MarshallOfSound pushed a commit that referenced this pull request Aug 25, 2026
#53156)

fix: don't kill the primary instance on large second-instance messages (#52628)

The POSIX process singleton read a second instance's notification into
a fixed 32 KiB buffer and gave up as soon as writing to the socket would
block. Command lines or additionalData payloads beyond those limits
were either silently truncated or, when the write couldn't complete,
made the second instance kill the primary process as unresponsive.

(cherry picked from commit 1652d8e)
@trop trop Bot added merged/43-x-y PR was merged to the "43-x-y" branch. and removed in-flight/43-x-y labels Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

45-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants