0

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?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 1
    No this is not normal. Do you have access to console logs of your server? There must be a panic or some other runtime error to cause the server to stop. The console would give clues to why that is. Liberal use of `log` will help too. – colm.anseo May 12 '19 at 20:45
  • @colminator Im using amazon aws ec2 instance and I own it. I just need you to tell me where to find it. :/ – Karina sarkisovae May 12 '19 at 20:50
  • 1
    AWS: [Getting Console Output](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-console.html) – colm.anseo May 12 '19 at 20:54

3 Answers3

2
  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

TBouder
  • 2,539
  • 1
  • 14
  • 29
Solorad
  • 904
  • 9
  • 21
0

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.

0

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?

ukurik
  • 79
  • 5