Skip to content

Commit 0eeae65

Browse files
committed
maybe fix of grpc DATA RACE on reading trailer metadata and closing grpc stream
1 parent 6cc535c commit 0eeae65

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

internal/table/session.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,13 @@ func (s *session) StreamReadTable(
926926
return nil, xerrors.WithStackTrace(err)
927927
}
928928

929-
if checkHintSessionClose(stream.Trailer()) {
930-
s.SetStatus(options.SessionClosing)
929+
select {
930+
case <-stream.Context().Done():
931+
// nop
932+
default:
933+
if checkHintSessionClose(stream.Trailer()) {
934+
s.SetStatus(options.SessionClosing)
935+
}
931936
}
932937

933938
return scanner.NewStream(
@@ -1010,8 +1015,13 @@ func (s *session) StreamExecuteScanQuery(
10101015
return nil, xerrors.WithStackTrace(err)
10111016
}
10121017

1013-
if checkHintSessionClose(stream.Trailer()) {
1014-
s.SetStatus(options.SessionClosing)
1018+
select {
1019+
case <-stream.Context().Done():
1020+
// nop
1021+
default:
1022+
if checkHintSessionClose(stream.Trailer()) {
1023+
s.SetStatus(options.SessionClosing)
1024+
}
10151025
}
10161026

10171027
return scanner.NewStream(

0 commit comments

Comments
 (0)