Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions router/core/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ type Executor struct {
TrackUsageInfo bool
}

// Close releases schema and planner references held by the executor so a replaced
// graph mux can be garbage-collected after config reload.
func (e *Executor) Close() {
if e == nil {
return
}
e.ClientSchema = nil
e.RouterSchema = nil
e.PlanConfig = plan.Configuration{}
e.RenameTypeNames = nil
e.Resolver = nil
Comment on lines +60 to +64

@dkorittki dkorittki Jun 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is websockets use this Executor and they are closed async. When this function is called websocket connections are still alive (got signaled to close but might take a moment) and might use the Executor, which has just nilled its components. It can cause nil panics or unwanted errors at least. I need to check this in more depth and how to solve it.

@dkorittki dkorittki Jun 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
e.Resolver = nil

I think we can exclude this one. Compared to the other fields it's not heavy and reduces the risk surface. Also this executor instance the pointer points to is referenced by other pointers in other places as well (the WS handler/graphql handler), which is still active when we are here. So GC can't clean it up immediately anyways.

EDIT: Also fixed by #3010 but review there still pending

}

type ExecutorBuildOptions struct {
EngineConfig *nodev1.EngineConfiguration
Subgraphs []*nodev1.Subgraph
Expand Down
37 changes: 37 additions & 0 deletions router/core/executor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package core

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/wundergraph/graphql-go-tools/v2/pkg/ast"
"github.com/wundergraph/graphql-go-tools/v2/pkg/engine/plan"
)

func TestExecutorCloseReleasesSchemaReferences(t *testing.T) {
t.Parallel()

executor := &Executor{
ClientSchema: &ast.Document{},
RouterSchema: &ast.Document{},
PlanConfig: plan.Configuration{DataSources: []plan.DataSource{nil}},
RenameTypeNames: nil,
}

executor.Close()

require.Nil(t, executor.ClientSchema)
require.Nil(t, executor.RouterSchema)
require.Empty(t, executor.PlanConfig.DataSources)
require.Nil(t, executor.RenameTypeNames)
require.Nil(t, executor.Resolver)
}

func TestExecutorCloseNilSafe(t *testing.T) {
t.Parallel()

var executor *Executor
require.NotPanics(t, func() {
executor.Close()
})
}
8 changes: 8 additions & 0 deletions router/core/graph_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ type graphMux struct {
mux *chi.Mux
reused atomic.Bool

executor *Executor

planCache *ristretto.Cache[uint64, *planWithMetaData]
planFallbackCache *slowplancache.Cache[*planWithMetaData]
persistedOperationCache *ristretto.Cache[uint64, NormalizationCacheEntry]
Expand Down Expand Up @@ -971,6 +973,11 @@ func (s *graphMux) Shutdown(ctx context.Context) error {
s.validationCache.Close()
s.operationHashCache.Close()

if s.executor != nil {
s.executor.Close()
s.executor = nil
}

var err error

if s.accessLogsFileLogger != nil {
Expand Down Expand Up @@ -1497,6 +1504,7 @@ func (s *graphServer) buildGraphMux(
if err != nil {
return nil, fmt.Errorf("failed to build plan configuration: %w", err)
}
gm.executor = executor

s.pubSubProviders = providers
if pubSubStartupErr := s.startupPubSubProviders(s.graphServerCtx); pubSubStartupErr != nil {
Expand Down
Loading