MCPcopy
hub / github.com/grpc/grpc-go / finish

Method finish

stream.go:1069–1121  ·  view source on GitHub ↗
(err error)

Source from the content-addressed store, hash-verified

1067}
1068
1069func (cs *clientStream) finish(err error) {
1070 if err == io.EOF {
1071 // Ending a stream with EOF indicates a success.
1072 err = nil
1073 }
1074 cs.mu.Lock()
1075 if cs.finished {
1076 cs.mu.Unlock()
1077 return
1078 }
1079 cs.finished = true
1080 cs.commitAttemptLocked()
1081 if cs.attempt != nil {
1082 cs.attempt.finish(err)
1083 // after functions all rely upon having a stream.
1084 if cs.attempt.transportStream != nil {
1085 for _, o := range cs.opts {
1086 o.after(cs.callInfo, cs.attempt)
1087 }
1088 }
1089 }
1090
1091 cs.mu.Unlock()
1092 // Only one of cancel or trailer needs to be logged.
1093 if len(cs.binlogs) != 0 {
1094 switch err {
1095 case errContextCanceled, errContextDeadline, ErrClientConnClosing:
1096 c := &binarylog.Cancel{
1097 OnClientSide: true,
1098 }
1099 for _, binlog := range cs.binlogs {
1100 binlog.Log(cs.ctx, c)
1101 }
1102 default:
1103 logEntry := &binarylog.ServerTrailer{
1104 OnClientSide: true,
1105 Trailer: cs.Trailer(),
1106 Err: err,
1107 }
1108 if peer, ok := peer.FromContext(cs.Context()); ok {
1109 logEntry.PeerAddr = peer.Addr
1110 }
1111 for _, binlog := range cs.binlogs {
1112 binlog.Log(cs.ctx, logEntry)
1113 }
1114 }
1115 }
1116 if err == nil {
1117 cs.retryThrottler.successfulRPC()
1118 }
1119 endOfClientStream(cs.cc, err, cs.opts...)
1120 cs.cancel()
1121}
1122
1123func (a *csAttempt) sendMsg(m any, hdr []byte, payld mem.BufferSlice, dataLength, payloadLength int) error {
1124 cs := a.cs

Callers 5

withRetryMethod · 0.95
HeaderMethod · 0.95
SendMsgMethod · 0.95
RecvMsgMethod · 0.95

Calls 12

commitAttemptLockedMethod · 0.95
TrailerMethod · 0.95
ContextMethod · 0.95
FromContextFunction · 0.92
endOfClientStreamFunction · 0.85
successfulRPCMethod · 0.80
cancelMethod · 0.80
afterMethod · 0.65
LogMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected