Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/goPublic

Commitb315b7f

Browse files
adgrsc
authored andcommitted
[release-branch.go1.1] time: prevent a panic from leaving the timer mutex held
««« CL 10373047 / 974a69ed9fcftime: prevent a panic from leaving the timer mutex heldWhen deleting a timer, a panic due to nil derefwould leave a lock held, possibly leading to a deadlockin a defer. Instead return false on a nil timer.Fixes#5745.R=golang-dev, daniel.morsing, dvyukov, rsc, iantCC=golang-devhttps://golang.org/cl/10373047»»»Update#5928R=golang-dev, daveCC=golang-devhttps://golang.org/cl/11666046
1 parente33810b commitb315b7f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

‎src/pkg/runtime/time.goc‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ runtime·deltimer(Timer *t)
131131
{
132132
int32 i;
133133

134+
// Dereference t so that any panic happens before the lock is held.
135+
// Discard result, because t might be moving in the heap.
136+
i = t->i;
137+
USED(i);
138+
134139
runtime·lock(&timers);
135140

136141
// t may not be registered anymore and may have

‎src/pkg/time/sleep_test.go‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,23 @@ func TestOverflowSleep(t *testing.T) {
314314
t.Fatalf("negative timeout didn't fire")
315315
}
316316
}
317+
318+
// Test that a panic while deleting a timer does not leave
319+
// the timers mutex held, deadlocking a ticker.Stop in a defer.
320+
funcTestIssue5745(t*testing.T) {
321+
ticker:=NewTicker(Hour)
322+
deferfunc() {
323+
// would deadlock here before the fix due to
324+
// lock taken before the segfault.
325+
ticker.Stop()
326+
327+
ifr:=recover();r==nil {
328+
t.Error("Expected panic, but none happened.")
329+
}
330+
}()
331+
332+
// cause a panic due to a segfault
333+
vartimer*Timer
334+
timer.Stop()
335+
t.Error("Should be unreachable.")
336+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp