gRPC Server stops for no reason

Asked by At

My Go gRPC Server stops without I stop it by myself. Right now I need to start the server again by entering the command "go run server.go" whenever I see it not responding every 30 or 60 minutes.

Is this normal? Do I need to restart the server after specific amount of time?

3 Answers

Shahed Ahmed On

I'm studying golang recently, I found go lang error handling different. If you want it will not force you to use err, and bad part is it will not show you anything. So please check your programs have any error or not. And also for experts help you need to be more clear about question. Show some code or indication than people can observe where is the problem. Just saying my program crashed will help you by anything.

kalvan On

Try these options 1. Check your logs of what happens before it exits(Dump the logs to a file to verify the issue) 2. Did you add any external package to the codebase which caused this?

Solorad On
  1. You can add in your handler recovery part
defer func() {
   if err := recover(); err != nil {
      log.Errorf("Recovered from err: %v\n %s", err, debug.Stack())
  1. More than that: there are specific middleware for catching such panic: From documentation:
import (
    panichandler ""

func main() {
    uIntOpt := grpc.UnaryInterceptor(panichandler.UnaryPanicHandler)
    sIntOpt := grpc.StreamInterceptor(panichandler.StreamPanicHandler)
    grpc.NewServer(uIntOpt, sIntOpt)

The second approach is more reliable when recovery handler approach is faster to add