fix:#56 added update for grpc

This commit is contained in:
Elmar Kresse
2024-10-06 20:11:03 +02:00
parent a12f9590f3
commit d8a7cc5387
10 changed files with 68 additions and 11 deletions

View File

@@ -2,8 +2,10 @@ package grpc
import (
"github.com/pocketbase/pocketbase"
"google.golang.org/grpc/keepalive"
"log"
"net"
"time"
"google.golang.org/grpc"
pb "htwkalender/common/genproto/modules"
@@ -14,7 +16,20 @@ func StartGRPCServer(app *pocketbase.PocketBase) {
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
s := grpc.NewServer(
grpc.KeepaliveParams(keepalive.ServerParameters{
MaxConnectionIdle: 5 * time.Minute, // Idle timeout before closing connection
MaxConnectionAge: 30 * time.Minute, // Max time before connection is closed
MaxConnectionAgeGrace: 5 * time.Minute, // Allow grace period before closing
Time: 2 * time.Minute, // Ping the client every 2 minutes
Timeout: 20 * time.Second, // Wait 20 seconds for ping ack
}),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: 1 * time.Minute, // Minimum time between pings from clients
PermitWithoutStream: true, // Don't allow pings when there are no active RPCs
}),
grpc.MaxConcurrentStreams(0),
)
pb.RegisterModuleServiceServer(s, &ModuleServiceHandler{
app: app,