Skip to content

Commit 294df40

Browse files
committed
move calling stats handlers into closure to avoid holding two locks
1 parent 2fe9a4f commit 294df40

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

internal/transport/handler_server.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,15 @@ func (ht *serverHandlerTransport) writeStatus(s *ServerStream, st *status.Status
272272
}
273273
}
274274
}
275-
})
276-
277-
if err == nil { // transport has not been closed
278275
// Note: The trailer fields are compressed with hpack after this call returns.
279276
// No WireLength field is set here.
280-
s.hdrMu.Lock()
281277
for _, sh := range ht.stats {
282278
sh.HandleRPC(s.Context(), &stats.OutTrailer{
283279
Trailer: s.trailer.Copy(),
284280
})
285281
}
286-
s.hdrMu.Unlock()
287-
}
282+
})
283+
288284
ht.Close(errors.New("finished writing status"))
289285
return err
290286
}

0 commit comments

Comments
 (0)