Skip to content

Commit 6ee739d

Browse files
committed
runtime: fix deadlock detector false negative
The issue was that scvg is assigned *after* the scavenger goroutine is started, so when the scavenger calls entersyscall() the g==scvg check can fail. Fixes #5025. R=golang-dev, iant CC=golang-dev https://golang.org/cl/7629045
1 parent 7f070af commit 6ee739d

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/pkg/runtime/mheap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ runtime·MHeap_Scavenger(void)
409409
bool trace;
410410
Note note, *notep;
411411

412+
g->issystem = true;
413+
g->isbackground = true;
414+
412415
// If we go two minutes without a garbage collection, force one to run.
413416
forcegc = 2*60*1e9;
414417
// If a span goes unused for 5 minutes after a garbage collection,

src/pkg/runtime/proc.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ M* runtime·extram;
7171
int8* runtime·goos;
7272
int32 runtime·ncpu;
7373
static int32 newprocs;
74-
// Keep trace of scavenger's goroutine for deadlock detection.
75-
static G *scvg;
7674

7775
void runtime·mstart(void);
7876
static void runqput(P*, G*);
@@ -174,8 +172,7 @@ runtime·main(void)
174172
runtime·lockOSThread();
175173
if(m != &runtime·m0)
176174
runtime·throw("runtime·main not on m0");
177-
scvg = runtime·newproc1(&scavenger, nil, 0, 0, runtime·main);
178-
scvg->issystem = true;
175+
runtime·newproc1(&scavenger, nil, 0, 0, runtime·main);
179176
main·init();
180177
runtime·unlockOSThread();
181178

@@ -1265,7 +1262,7 @@ void
12651262

12661263
p = releasep();
12671264
handoffp(p);
1268-
if(g == scvg) // do not consider blocked scavenger for deadlock detection
1265+
if(g->isbackground) // do not consider blocked scavenger for deadlock detection
12691266
inclocked(1);
12701267
runtime·gosave(&g->sched); // re-save for traceback
12711268
}
@@ -1297,7 +1294,7 @@ runtime·exitsyscall(void)
12971294
return;
12981295
}
12991296

1300-
if(g == scvg) // do not consider blocked scavenger for deadlock detection
1297+
if(g->isbackground) // do not consider blocked scavenger for deadlock detection
13011298
inclocked(-1);
13021299
// Try to get any other idle P.
13031300
m->p = nil;
@@ -1899,7 +1896,7 @@ checkdead(void)
18991896
}
19001897
grunning = 0;
19011898
for(gp = runtime·allg; gp; gp = gp->alllink) {
1902-
if(gp == scvg)
1899+
if(gp->isbackground)
19031900
continue;
19041901
s = gp->status;
19051902
if(s == Gwaiting)

src/pkg/runtime/runtime.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ struct G
235235
int8* waitreason; // if status==Gwaiting
236236
G* schedlink;
237237
bool ispanic;
238-
bool issystem;
239-
int8 raceignore; // ignore race detection events
238+
bool issystem; // do not output in stack dump
239+
bool isbackground; // ignore in deadlock detector
240+
int8 raceignore; // ignore race detection events
240241
M* m; // for debuggers, but offset not hard-coded
241242
M* lockedm;
242243
int32 sig;

0 commit comments

Comments
 (0)