Skip to content

Commit

Permalink
Set gateway timeout to match idle timeout value.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Jan 5, 2019
1 parent ee0649a commit f59989e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http:https://keepachangelog.com) and this project uses [semantic versioning](http:https://semver.org).

## [Unreleased]
### Fixed
- Set gateway timeout to match idle timeout value.

## [2.3.1] - 2019-01-04
### Added
Expand Down
12 changes: 11 additions & 1 deletion server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type ApiServer struct {
}

func StartApiServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.DB, jsonpbMarshaler *jsonpb.Marshaler, jsonpbUnmarshaler *jsonpb.Unmarshaler, config Config, socialClient *social.Client, leaderboardCache LeaderboardCache, leaderboardRankCache LeaderboardRankCache, sessionRegistry *SessionRegistry, matchRegistry MatchRegistry, matchmaker Matchmaker, tracker Tracker, router MessageRouter, pipeline *Pipeline, runtime *Runtime) *ApiServer {
grpcRuntime.DefaultContextTimeout = time.Duration(config.GetSocket().IdleTimeoutMs) * time.Millisecond

serverOpts := []grpc.ServerOption{
grpc.StatsHandler(&ocgrpc.ServerHandler{IsPublicEndpoint: true}),
grpc.MaxRecvMsgSize(int(config.GetSocket().MaxMessageSizeBytes)),
Expand Down Expand Up @@ -183,7 +185,15 @@ func StartApiServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.DB, j
r.Body = http.MaxBytesReader(w, r.Body, maxMessageSizeBytes)
handlerWithCompressResponse.ServeHTTP(w, r)
})
grpcGatewayRouter.NewRoute().Handler(handlerWithMaxBody)
grpcGatewayRouter.NewRoute().HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Do not allow clients to set certain headers.
// Currently disallowed headers:
// "Grpc-Timeout"
r.Header.Del("Grpc-Timeout")

// Allow GRPC Gateway to handle the request.
handlerWithMaxBody.ServeHTTP(w, r)
})

// Enable CORS on all requests.
CORSHeaders := handlers.AllowedHeaders([]string{"Authorization", "Content-Type", "User-Agent"})
Expand Down

0 comments on commit f59989e

Please sign in to comment.