diff --git a/router/core/router.go b/router/core/router.go index a2ef32029..fec7458a0 100644 --- a/router/core/router.go +++ b/router/core/router.go @@ -6,6 +6,7 @@ import ( "crypto/x509" "errors" "fmt" + "github.com/wundergraph/graphql-go-tools/v2/pkg/netpoll" "net" "net/http" "net/url" @@ -515,6 +516,26 @@ func NewRouter(opts ...Option) (*Router, error) { r.logger.Info("Kafka Event source enabled", zap.String("provider_id", source.ID), zap.Strings("brokers", source.Brokers)) } + if !r.engineExecutionConfiguration.EnableNetPoll { + r.logger.Warn("Net poller is disabled by configuration. Falling back to less efficient connection handling method.") + } else if err := netpoll.Supported(); err != nil { + + // Disable netPoll if it's not supported. This flag is used everywhere to decide whether to use netPoll or not. + r.engineExecutionConfiguration.EnableNetPoll = false + + if errors.Is(err, netpoll.ErrUnsupported) { + r.logger.Warn( + "Net poller is only available on Linux and MacOS. Falling back to less efficient connection handling method.", + zap.Error(err), + ) + } else { + r.logger.Warn( + "Net poller is not functional by the environment. Ensure that the system supports epoll/kqueue and that necessary syscall permissions are granted. Falling back to less efficient connection handling method.", + zap.Error(err), + ) + } + } + return r, nil } diff --git a/router/core/websocket.go b/router/core/websocket.go index 5384605b8..53eae6540 100644 --- a/router/core/websocket.go +++ b/router/core/websocket.go @@ -122,30 +122,15 @@ func NewWebsocketMiddleware(ctx context.Context, opts WebsocketMiddlewareOptions handler.forwardQueryParamsConfig.withRegexAllowList = len(handler.forwardQueryParamsConfig.regexAllowList) > 0 } if opts.EnableNetPoll { - if err := netpoll.Supported(); err != nil { - if errors.Is(err, netpoll.ErrUnsupported) { - opts.Logger.Warn( - "Net poller is only available on Linux and MacOS. Falling back to less efficient connection handling method.", - zap.Error(err), - ) - } else { - opts.Logger.Warn( - "Net poller is not functional by the environment. Ensure that the system supports epoll/kqueue and that necessary syscall permissions are granted. Falling back to less efficient connection handling method.", - zap.Error(err), - ) - } - } else { - poller, err := netpoll.NewPoller(opts.NetPollConnBufferSize, opts.NetPollTimeout) - if err == nil { - opts.Logger.Debug("Net poller is available") + poller, err := netpoll.NewPoller(opts.NetPollConnBufferSize, opts.NetPollTimeout) + if err == nil { + opts.Logger.Debug("Net poller is available") - handler.netPoll = poller - handler.connections = make(map[int]*WebSocketConnectionHandler) - go handler.runPoller() - } + handler.netPoll = poller + handler.connections = make(map[int]*WebSocketConnectionHandler) + go handler.runPoller() } - } else { - opts.Logger.Warn("Net poller is disabled by configuration. Falling back to less efficient connection handling method.") + } return func(next http.Handler) http.Handler {