Skip to content

Commit 1f70736

Browse files
authored
Merge pull request #417 from dfuse-io/fix/subscription-panic-in-resolver
Fixed `reflect.Value.Type on zero Value` panic when subscription resolver itself panics
2 parents 3c9ac91 + 5940bf3 commit 1f70736

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

internal/exec/exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type extensionser interface {
3939
}
4040

4141
func makePanicError(value interface{}) *errors.QueryError {
42-
return errors.Errorf("graphql: panic occurred: %v", value)
42+
return errors.Errorf("panic occurred: %v", value)
4343
}
4444

4545
func (r *Request) Execute(ctx context.Context, s *resolvable.Schema, op *query.Operation) ([]byte, []*errors.QueryError) {
@@ -326,7 +326,7 @@ func (r *Request) execList(ctx context.Context, sels []selected.Selection, typ *
326326
r.execSelectionSet(ctx, sels, typ.OfType, &pathSegment{path, i}, s, resolver.Index(i), &entryouts[i])
327327
}(i)
328328
}
329-
for i := 0; i < concurrency;i++ {
329+
for i := 0; i < concurrency; i++ {
330330
sem <- struct{}{}
331331
}
332332
} else {

internal/exec/subscribe.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func (r *Request) Subscribe(ctx context.Context, s *resolvable.Schema, op *query
6161
}
6262
}()
6363

64+
// Handles the case where the locally executed func above panicked
65+
if len(r.Request.Errs) > 0 {
66+
return sendAndReturnClosed(&Response{Errors: r.Request.Errs})
67+
}
68+
6469
if f == nil {
6570
return sendAndReturnClosed(&Response{Errors: []*errors.QueryError{err}})
6671
}

subscription_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,33 @@ func TestSchemaSubscribe_CustomResolverTimeout(t *testing.T) {
543543
},
544544
})
545545
}
546+
547+
type subscriptionsPanicInResolver struct{}
548+
549+
func (r *subscriptionsPanicInResolver) OnPanic() <-chan string {
550+
panic("subscriptionsPanicInResolver")
551+
}
552+
553+
func TestSchemaSubscribe_PanicInResolver(t *testing.T) {
554+
r := &struct {
555+
*subscriptionsPanicInResolver
556+
}{
557+
subscriptionsPanicInResolver: &subscriptionsPanicInResolver{},
558+
}
559+
gqltesting.RunSubscribe(t, &gqltesting.TestSubscription{
560+
Schema: graphql.MustParseSchema(`
561+
type Query {}
562+
type Subscription {
563+
onPanic : String!
564+
}
565+
`, r),
566+
Query: `
567+
subscription {
568+
onPanic
569+
}
570+
`,
571+
ExpectedResults: []gqltesting.TestResponse{
572+
{Errors: []*qerrors.QueryError{{Message: "panic occurred: subscriptionsPanicInResolver"}}},
573+
},
574+
})
575+
}

0 commit comments

Comments
 (0)