Skip to content

Commit

Permalink
Fix SIGSEGV when client subs to multiple fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Maquet committed Jun 13, 2020
1 parent dae41bd commit c80e625
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/exec/subscribe.go
Expand Up @@ -55,6 +55,10 @@ func (r *Request) Subscribe(ctx context.Context, s *resolvable.Schema, op *query
}
}()

if f == nil {
return sendAndReturnClosed(&Response{Errors: []*errors.QueryError{err}})
}

if err != nil {
if _, nonNullChild := f.field.Type.(*common.NonNull); nonNullChild {
return sendAndReturnClosed(&Response{Errors: []*errors.QueryError{err}})
Expand Down
34 changes: 34 additions & 0 deletions subscription_test.go
Expand Up @@ -56,6 +56,10 @@ func (r *helloSaidResolver) HelloSaid(ctx context.Context) (chan *helloSaidEvent
return c, nil
}

func (r *rootResolver) OtherField(ctx context.Context) <-chan int32 {
return make(chan int32)
}

func (r *helloSaidEventResolver) Msg() (string, error) {
return r.msg, r.err
}
Expand Down Expand Up @@ -416,6 +420,36 @@ func TestRootOperations_validSubscriptionSchema(t *testing.T) {
})
}

func TestError_multiple_subscription_fields(t *testing.T) {
gqltesting.RunSubscribes(t, []*gqltesting.TestSubscription{
{
Name: "Explicit schema without subscription field",
Schema: graphql.MustParseSchema(`
schema {
query: Query
subscription: Subscription
}
type Query {
hello: String!
}
type Subscription {
helloSaid: HelloSaidEvent!
otherField: Int!
}
type HelloSaidEvent {
msg: String!
}
`, &rootResolver{helloSaidResolver: &helloSaidResolver{upstream: closedUpstream(&helloSaidEventResolver{msg: "Hello world!"})}}),
Query: `subscription { helloSaid { msg } otherField }`,
ExpectedResults: []gqltesting.TestResponse{
{
Errors: []*qerrors.QueryError{qerrors.Errorf("can subscribe to at most one subscription at a time")},
},
},
},
})
}

const schema = `
schema {
subscription: Subscription,
Expand Down

0 comments on commit c80e625

Please sign in to comment.