Karina sarkisovae
Karina sarkisovae

Reputation: 59

gRPC Server stops for no reason

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?

Upvotes: 0

Views: 2524

Answers (3)

Solorad
Solorad

Reputation: 914

  1. You can add in your handler recovery part
import    "runtime/debug"

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: https://github.com/kazegusuri/grpc-panic-handler From documentation:
import (
    panichandler "github.com/kazegusuri/grpc-panic-handler"
)

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

Upvotes: 2

ukurik
ukurik

Reputation: 79

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?

Upvotes: 0

Shahed Ahmed
Shahed Ahmed

Reputation: 83

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.

Upvotes: 0

Related Questions