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

Method processUnaryRPC

server.go:1260–1552  ·  view source on GitHub ↗
(ctx context.Context, stream *transport.ServerStream, info *serviceInfo, md *MethodDesc, trInfo *traceInfo)

Source from the content-addressed store, hash-verified

1258}
1259
1260func (s *Server) processUnaryRPC(ctx context.Context, stream *transport.ServerStream, info *serviceInfo, md *MethodDesc, trInfo *traceInfo) (err error) {
1261 sh := s.statsHandler
1262 if sh != nil || trInfo != nil || channelz.IsOn() {
1263 if channelz.IsOn() {
1264 s.incrCallsStarted()
1265 }
1266 var statsBegin *stats.Begin
1267 if sh != nil {
1268 statsBegin = &stats.Begin{
1269 BeginTime: time.Now(),
1270 IsClientStream: false,
1271 IsServerStream: false,
1272 }
1273 sh.HandleRPC(ctx, statsBegin)
1274 }
1275 if trInfo != nil {
1276 trInfo.tr.LazyLog(&trInfo.firstLine, false)
1277 }
1278 // The deferred error handling for tracing, stats handler and channelz are
1279 // combined into one function to reduce stack usage -- a defer takes ~56-64
1280 // bytes on the stack, so overflowing the stack will require a stack
1281 // re-allocation, which is expensive.
1282 //
1283 // To maintain behavior similar to separate deferred statements, statements
1284 // should be executed in the reverse order. That is, tracing first, stats
1285 // handler second, and channelz last. Note that panics *within* defers will
1286 // lead to different behavior, but that's an acceptable compromise; that
1287 // would be undefined behavior territory anyway.
1288 defer func() {
1289 if trInfo != nil {
1290 if err != nil && err != io.EOF {
1291 trInfo.tr.LazyLog(&fmtStringer{"%v", []any{err}}, true)
1292 trInfo.tr.SetError()
1293 }
1294 trInfo.tr.Finish()
1295 }
1296
1297 if sh != nil {
1298 end := &stats.End{
1299 BeginTime: statsBegin.BeginTime,
1300 EndTime: time.Now(),
1301 }
1302 if err != nil && err != io.EOF {
1303 end.Error = toRPCErr(err)
1304 }
1305 sh.HandleRPC(ctx, end)
1306 }
1307
1308 if channelz.IsOn() {
1309 if err != nil && err != io.EOF {
1310 s.incrCallsFailed()
1311 } else {
1312 s.incrCallsSucceeded()
1313 }
1314 }
1315 }()
1316 }
1317 var binlogs []binarylog.MethodLogger

Callers 1

handleStreamMethod · 0.95

Calls 15

incrCallsStartedMethod · 0.95
incrCallsFailedMethod · 0.95
incrCallsSucceededMethod · 0.95
TypeMethod · 0.95
NameMethod · 0.95
freeMethod · 0.95
getCodecMethod · 0.95
sendResponseMethod · 0.95
IsOnFunction · 0.92
GetMethodLoggerFunction · 0.92
FromIncomingContextFunction · 0.92
FromContextFunction · 0.92

Tested by

no test coverage detected