Commit 79940f82 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Improve default config for large message sizes.

parent 9c028959
Loading
Loading
Loading
Loading
+8 −11
Original line number Diff line number Diff line
@@ -15,27 +15,21 @@
package server

import (
	"compress/flate"
	"compress/gzip"
	"context"
	"crypto"
	"crypto/tls"
	"crypto/x509"
	"database/sql"
	"encoding/base64"
	"fmt"
	"google.golang.org/protobuf/encoding/protojson"
	"math"
	"net"
	"net/http"
	"strings"
	"time"

	"github.com/heroiclabs/nakama-common/api"

	"google.golang.org/grpc/peer"

	"crypto/tls"

	"compress/flate"
	"compress/gzip"

	"github.com/dgrijalva/jwt-go"
	"github.com/gofrs/uuid"
	"github.com/golang/protobuf/jsonpb"
@@ -43,6 +37,7 @@ import (
	"github.com/gorilla/handlers"
	"github.com/gorilla/mux"
	grpcgw "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
	"github.com/heroiclabs/nakama-common/api"
	"github.com/heroiclabs/nakama/v3/apigrpc"
	"github.com/heroiclabs/nakama/v3/social"
	"go.uber.org/zap"
@@ -51,7 +46,9 @@ import (
	"google.golang.org/grpc/credentials"
	_ "google.golang.org/grpc/encoding/gzip" // enable gzip compression on server for grpc
	"google.golang.org/grpc/metadata"
	"google.golang.org/grpc/peer"
	"google.golang.org/grpc/status"
	"google.golang.org/protobuf/encoding/protojson"
)

// Used as part of JSON input validation.
@@ -178,7 +175,7 @@ func StartApiServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.DB, j
	dialOpts := []grpc.DialOption{
		grpc.WithDefaultCallOptions(
			grpc.MaxCallSendMsgSize(int(config.GetSocket().MaxRequestSizeBytes)),
			grpc.MaxCallRecvMsgSize(1024*1024*128),
			grpc.MaxCallRecvMsgSize(math.MaxInt32),
		),
		//grpc.WithStatsHandler(&ocgrpc.ClientHandler{}),
	}
+5 −7
Original line number Diff line number Diff line
@@ -167,6 +167,9 @@ func CheckConfig(logger *zap.Logger, config Config) map[string]string {
	if config.GetSocket().MaxMessageSizeBytes < 1 {
		logger.Fatal("Socket max message size bytes must be >= 1", zap.Int64("socket.max_message_size_bytes", config.GetSocket().MaxMessageSizeBytes))
	}
	if config.GetSocket().MaxRequestSizeBytes < 1 {
		logger.Fatal("Socket max request size bytes must be >= 1", zap.Int64("socket.max_request_size_bytes", config.GetSocket().MaxRequestSizeBytes))
	}
	if config.GetSocket().ReadBufferSizeBytes < 1 {
		logger.Fatal("Socket read buffer size bytes must be >= 1", zap.Int("socket.read_buffer_size_bytes", config.GetSocket().ReadBufferSizeBytes))
	}
@@ -342,11 +345,6 @@ func CheckConfig(logger *zap.Logger, config Config) map[string]string {
		config.GetSocket().TLSCert = []tls.Certificate{cert}
	}

	// Set backwards-compatible defaults if overrides are not used.
	if config.GetSocket().MaxRequestSizeBytes <= 0 {
		config.GetSocket().MaxRequestSizeBytes = config.GetSocket().MaxMessageSizeBytes
	}

	return configWarnings
}

@@ -630,7 +628,7 @@ func NewSocketConfig() *SocketConfig {
		Address:              "",
		Protocol:             "tcp",
		MaxMessageSizeBytes:  4096,
		MaxRequestSizeBytes:  0,
		MaxRequestSizeBytes:  262_144, // 256 KB.
		ReadBufferSizeBytes:  4096,
		WriteBufferSizeBytes: 4096,
		ReadTimeoutMs:        10 * 1000,
@@ -840,7 +838,7 @@ type ConsoleConfig struct {
func NewConsoleConfig() *ConsoleConfig {
	return &ConsoleConfig{
		Port:                7351,
		MaxMessageSizeBytes: 4096,
		MaxMessageSizeBytes: 4_194_304, // 4 MB.
		ReadTimeoutMs:       10 * 1000,
		WriteTimeoutMs:      60 * 1000,
		IdleTimeoutMs:       300 * 1000,
+3 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import (
	"database/sql"
	"fmt"
	"io/ioutil"
	"math"
	"net"
	"net/http"
	"net/http/pprof"
@@ -27,7 +28,7 @@ import (
	"strings"
	"time"

	jwt "github.com/dgrijalva/jwt-go"
	"github.com/dgrijalva/jwt-go"
	"google.golang.org/protobuf/encoding/protojson"

	"github.com/gorilla/handlers"
@@ -158,7 +159,7 @@ func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.D
	dialOpts := []grpc.DialOption{
		grpc.WithDefaultCallOptions(
			grpc.MaxCallSendMsgSize(int(config.GetConsole().MaxMessageSizeBytes)),
			grpc.MaxCallRecvMsgSize(int(config.GetConsole().MaxMessageSizeBytes)),
			grpc.MaxCallRecvMsgSize(math.MaxInt32),
		),
		grpc.WithInsecure(),
	}