You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running field resolver on tests with mock using github.com/stretchr/testify results in dead-lock, if the called function is not defined.
What did you expect?
My test should run smoothly, no dead-lock.
Minimal graphql.schema and models to reproduce
Create a type like below and define
type Timeout {
Name: String!
}
define a resolver on the field. If you have a resolver, a goroutine will be created to run the resolver. If inside this goroutine runtime.Goexit() is called , then we'll have a dead-lock.
versions
go run github.com/99designs/gqlgen version? v0.17.41
go version? go version go1.21.0 linux/amd64
Long Version
I have a web server which has many types. Many of these types have resolver on their fields. If you takes a look at the code, you will see that
// only one concurrent task, no need to spawn a goroutine or deal create waitgroups
d:=m.delayed[0]
m.Values[d.i] =d.f(ctx)
} elseiflen(m.delayed) >1 {
// more than one concurrent task, use the main goroutine to do one, only spawn goroutines for the others
varwg sync.WaitGroup
for_, d:=rangem.delayed[1:] {
wg.Add(1)
gofunc(ddelayedResult) {
m.Values[d.i] =d.f(ctx)
wg.Done()
}(d)
}
m.Values[m.delayed[0].i] =m.delayed[0].f(ctx)
wg.Wait()
}
}
a wait group is defined and it will run resolver functions in a separate goroutine. Once all the resolver functions are finished, wait group allows the code for move forward.
But Sometime Inside the resolver,I call a service which during a test a mock will be used. When the mock doesn't know what to return, it calls FailNow function on *testing.T which in turn calls runtime.Goexit() and it will kill the goroutine. This means that wg.Done() is not called and the application gets stuck at wg.Wait(). To fix this issue, I need to change:
What happened?
Running field resolver on tests with mock using github.com/stretchr/testify results in dead-lock, if the called function is not defined.
What did you expect?
My test should run smoothly, no dead-lock.
Minimal graphql.schema and models to reproduce
Create a type like below and define
type Timeout {
Name: String!
}
define a resolver on the field. If you have a resolver, a goroutine will be created to run the resolver. If inside this goroutine
runtime.Goexit()
is called , then we'll have a dead-lock.versions
go run github.com/99designs/gqlgen version
? v0.17.41go version
? go version go1.21.0 linux/amd64Long Version
I have a web server which has many types. Many of these types have resolver on their fields. If you takes a look at the code, you will see that
gqlgen/graphql/fieldset.go
Lines 37 to 57 in 24ea195
a wait group is defined and it will run resolver functions in a separate goroutine. Once all the resolver functions are finished, wait group allows the code for move forward.
But Sometime Inside the resolver,I call a service which during a test a mock will be used. When the mock doesn't know what to return, it calls
FailNow
function on*testing.T
which in turn callsruntime.Goexit()
and it will kill the goroutine. This means thatwg.Done()
is not called and the application gets stuck atwg.Wait()
. To fix this issue, I need to change:gqlgen/graphql/fieldset.go
Lines 48 to 51 in 24ea195
to
to make sure even if
runtime.Goexit()
is called, the test will exit instead of running forever.The text was updated successfully, but these errors were encountered: