[go] syscall: fix incorrect defer usage in acquireForkLock

0 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
10:03 AM (5 hours ago) 10:03 AM
to goph...@pubsubhelper.golang.org, feizaizheli, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

syscall: fix incorrect defer usage in acquireForkLock

The defer forkingLock.Unlock() at the start of acquireForkLock was problematic because:

1. When forking == 0, the function returns early (line 47), but the deferred Unlock() would still execute, which is correct behavior.

2. However, when hasWaitingReaders returns true, the function manually unlocks (line 65) and then re-locks (line 70) forkingLock. At the end of this path, the deferred Unlock() would execute again, causing a double unlock on forkingLock.

This fix replaces defer with explicit Unlock() calls at both exit points to ensure the lock is released exactly once per execution path.

This PR will be imported into Gerrit with the title and first
comment (this text) used to generate the subject and body of
the Gerrit change.

**Please ensure you adhere to every item in this list.**

More info can be found at https://github.com/golang/go/wiki/CommitMessage

+ The PR title is formatted as follows: `net/http: frob the quux before blarfing`
+ The package name goes before the colon
+ The part after the colon uses the verb tense + phrase that completes the blank in,
"This change modifies Go to ___________"
+ Lowercase verb after the colon
+ No trailing period
+ Keep the title as short as possible. ideally under 76 characters or shorter
+ No Markdown
+ The first PR comment (this one) is wrapped at 76 characters, unless it's
really needed (ASCII art, table, or long link)
+ If there is a corresponding issue, add either `Fixes #1234` or `Updates #1234`
(the latter if this is not a complete fix) to this comment
+ If referring to a repo other than `golang/go` you can use the
`owner/repo#issue_number` syntax: `Fixes golang/tools#1234`
+ We do not use Signed-off-by lines in Go. Please don't add them.
Our Gerrit server & GitHub bots enforce CLA compliance instead.
+ Delete these instructions once you have read and applied them
Change-Id: Ic513c749dd71ddaf9146d51f4b63dc4be40e86ed
GitHub-Last-Rev: 7056858b2aed4cf46df685e775d5be52f1c3e9c9
GitHub-Pull-Request: golang/go#77846

Change diff

diff --git a/src/syscall/forkpipe2.go b/src/syscall/forkpipe2.go
index bbecfda..051741f 100644
--- a/src/syscall/forkpipe2.go
+++ b/src/syscall/forkpipe2.go
@@ -38,12 +38,12 @@
// at the first fork and unlocked when there are no more forks.
func acquireForkLock() {
forkingLock.Lock()
- defer forkingLock.Unlock()

if forking == 0 {
// There is no current write lock on ForkLock.
ForkLock.Lock()
forking++
+ forkingLock.Unlock()
return
}

@@ -77,6 +77,7 @@
}

forking++
+ forkingLock.Unlock()
}

// releaseForkLock releases the conceptual write lock on ForkLock

Change information

Files:
  • M src/syscall/forkpipe2.go
Change size: XS
Delta: 1 file changed, 2 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ic513c749dd71ddaf9146d51f4b63dc4be40e86ed
Gerrit-Change-Number: 749820
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: feizaizheli <feiza...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
10:03 AM (5 hours ago) 10:03 AM
to feizaizheli, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems with your PR:

  1. Do you still have the GitHub PR instructions in your commit message text? The PR instructions should be deleted once you have applied them.
2. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.

Please address any problems by updating the GitHub PR.

When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

For more details, see:

(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ic513c749dd71ddaf9146d51f4b63dc4be40e86ed
    Gerrit-Change-Number: 749820
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: feizaizheli <feiza...@gmail.com>
    Gerrit-Comment-Date: Fri, 27 Feb 2026 15:03:53 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    10:05 AM (5 hours ago) 10:05 AM
    to feizaizheli, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Message from Gopher Robot

    Congratulations on opening your first change. Thank you for your contribution!

    Next steps:
    A maintainer will review your change and provide feedback. See
    https://go.dev/doc/contribute#review for more info and tips to get your
    patch through code review.

    Most changes in the Go project go through a few rounds of revision. This can be
    surprising to people new to the project. The careful, iterative review process
    is our way of helping mentor contributors and ensuring that their contributions
    have a lasting impact.

    During May-July and Nov-Jan the Go project is in a code freeze, during which
    little code gets reviewed or merged. If a reviewer responds with a comment like
    R=go1.11 or adds a tag like "wait-release", it means that this CL will be
    reviewed as part of the next development cycle. See https://go.dev/s/release
    for more details.

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ic513c749dd71ddaf9146d51f4b63dc4be40e86ed
    Gerrit-Change-Number: 749820
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: feizaizheli <feiza...@gmail.com>
    Gerrit-Comment-Date: Fri, 27 Feb 2026 15:05:40 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Gerrit Bot (Gerrit)

    unread,
    10:14 AM (5 hours ago) 10:14 AM
    to feizaizheli, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #2 to this change.
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ic513c749dd71ddaf9146d51f4b63dc4be40e86ed
    Gerrit-Change-Number: 749820
    Gerrit-PatchSet: 2
    unsatisfied_requirement
    open
    diffy

    Keith Randall (Gerrit)

    unread,
    11:39 AM (4 hours ago) 11:39 AM
    to feizaizheli, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Brad Fitzpatrick, Tobias Klauser, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Brad Fitzpatrick, Ian Lance Taylor and Tobias Klauser

    Keith Randall added 1 comment

    Patchset-level comments
    File-level comment, Patchset 2 (Latest):
    Keith Randall . unresolved

    The original code looks right to me.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Brad Fitzpatrick
    • Ian Lance Taylor
    • Tobias Klauser
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ic513c749dd71ddaf9146d51f4b63dc4be40e86ed
    Gerrit-Change-Number: 749820
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Keith Randall <k...@golang.org>
    Gerrit-CC: feizaizheli <feiza...@gmail.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Fri, 27 Feb 2026 16:39:22 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Ian Lance Taylor (Gerrit)

    unread,
    2:47 PM (1 hour ago) 2:47 PM
    to feizaizheli, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Brad Fitzpatrick, Tobias Klauser, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com

    Ian Lance Taylor abandoned this change.

    View Change

    Abandoned Thanks, but original code is correct.

    Ian Lance Taylor abandoned this change

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: abandon
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages