Closed Bug 2073819 Opened 2 months ago Closed 2 months ago

Subprocess leaks the parent's pipe ends when launching the child process fails

Categories

(Toolkit :: Async Tooling, defect)

defect

Tracking

()

RESOLVED FIXED
158 Branch
Tracking Status
firefox-esr153 --- fixed
firefox157 --- fixed
firefox158 --- fixed

People

(Reporter: spohl, Assigned: spohl)

References

Details

(Keywords: webext)

Attachments

(3 external files)

When IOUtils.launchProcess() throws inside subprocess_unix.worker.js, for example because the executable's interpreter is missing or posix_spawn refuses to start the program, spawn() disposes only the child's ends of the pipes it created. The parent's ends of stdin, stdout, stderr and the exit-sentinel pipe stay open until the worker happens to garbage-collect them. The Windows worker closes its pipes on failure; the Unix worker does not.

Measured with a script whose shebang points at a missing interpreter: 100 failed Subprocess.call() attempts grow the process from 11 to 413 open descriptors (four per attempt), while 100 successful launches grow it from 11 to 13.

An extension that keeps retrying a native messaging host whose launch fails leaks four descriptors per attempt. That appears to be the pipe leak behind the macOS 27 crashes in bug 2026491, where the parent process accumulates about one pipe pair per second.

The fix is to close the parent's pipe ends when the launch fails, with a regression test.

When IOUtils.launchProcess() throws, spawn() disposed only the child's ends of the pipes it had just created. The parent's ends of stdin, stdout, stderr and the exit sentinel stayed open until the worker garbage-collected them, four descriptors per failed launch. An extension that keeps retrying a native messaging host whose launch fails can exhaust the process's descriptors this way. The Windows worker already closes its pipes on failure.

Attachment #9645484 - Attachment description: Bug 2073819: Close the parent's pipe ends when Subprocess fails to launch the child on Unix. r?rpl → Bug 2073819: Close the parent's pipe ends when Subprocess fails to launch the child on Unix. r?robwu

Could you request an uplift to ESR 153? As noted at https://bugzilla.mozilla.org/show_bug.cgi?id=2026491#c38 macOS 27 Golden Gate is much more prone to trigger this bug due to native messaging binaries that are suddenly incompatible due to the default ommission of Rosetta.

Keywords: webext
Pushed by spohl@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/d3e70cfe88a2 https://hg.mozilla.org/integration/autoland/rev/faa2abf86d51 Close the parent's pipe ends when Subprocess fails to launch the child on Unix. r=robwu

firefox-esr153 Uplift Approval Request

  • User impact if declined/Reason for urgency: Users who have extensions that rely on Intel-based binaries and upgrade to macOS 27 may crash in less than an hour of uptime due to the fact that macOS 27 has removed Rosetta by default. While it can be manually installed, this failure is not visible to the user and it isn't obvious that installing Rosetta would address it.
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: no
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: This simply closes pipes when a child failed to launch. There is no behavior change in the successful case and the patch adds a test.
  • String changes made/needed?: none
  • Is Android affected?: no
Attachment #9646474 - Flags: approval-mozilla-esr153?

When IOUtils.launchProcess() throws, spawn() disposed only the child's ends of the pipes it had just created. The parent's ends of stdin, stdout, stderr and the exit sentinel stayed open until the worker garbage-collected them, four descriptors per failed launch. An extension that keeps retrying a native messaging host whose launch fails can exhaust the process's descriptors this way. The Windows worker already closes its pipes on failure.

Original Revision: https://phabricator.services.mozilla.com/D327609

Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 158 Branch
Attachment #9646474 - Flags: approval-mozilla-esr153? → approval-mozilla-esr153+

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: Users who have extensions that rely on Intel-based binaries and upgrade to macOS 27 may crash in less than an hour of uptime due to the fact that macOS 27 has removed Rosetta by default. While it can be manually installed, this failure is not visible to the user and it isn't obvious that installing Rosetta would address it. This was found following a user report and debugging at https://bugzilla.mozilla.org/show_bug.cgi?id=2026491#c38
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: no
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: This simply closes pipes when a child failed to launch. There is no behavior change in the successful case and the patch adds a test.
  • String changes made/needed?: None
  • Is Android affected?: no
Attachment #9646945 - Flags: approval-mozilla-beta?

When IOUtils.launchProcess() throws, spawn() disposed only the child's ends of the pipes it had just created. The parent's ends of stdin, stdout, stderr and the exit sentinel stayed open until the worker garbage-collected them, four descriptors per failed launch. An extension that keeps retrying a native messaging host whose launch fails can exhaust the process's descriptors this way. The Windows worker already closes its pipes on failure.

Original Revision: https://phabricator.services.mozilla.com/D327609

Attachment #9646945 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
See Also: → 2082673
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: