Skip to content

Commit c99c545

Browse files
authored
fix: nil-pointer-dereference when the item is deleted during single subscription (#220)
On-behalf-of: @SAP [email protected] Signed-off-by: Artem Shcherbatiuk <[email protected]>
1 parent 0be9f3a commit c99c545

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

gateway/resolver/subscription.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ func (r *Service) runWatch(
186186
select {
187187
case <-ctx.Done():
188188
return
189-
case resultChannel <- singleObj.Object:
189+
case resultChannel <- func() interface{} {
190+
if singleObj == nil { // object will be nil in case it is deleted
191+
return nil
192+
}
193+
return singleObj.Object
194+
}():
190195
}
191196
} else {
192197
items := make([]unstructured.Unstructured, 0, len(previousObjects))

tests/gateway_test/subscription_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ func (suite *CommonTestSuite) TestSchemaSubscribe() {
2626
expectError bool
2727
}{
2828
{
29-
testName: "subscribe_deployment_and_create_deployment_OK",
29+
testName: "subscribe_create_and_delete_deployment_OK",
3030
subscribeQuery: SubscribeDeployment("my-new-deployment", false),
3131
setupFunc: func(ctx context.Context) {
3232
suite.createDeployment(ctx, "my-new-deployment", map[string]string{"app": "my-app"})
33+
suite.deleteDeployment(ctx, "my-new-deployment")
3334
},
34-
expectedEvents: 1,
35+
expectedEvents: 2,
3536
},
3637
{
3738
testName: "subscribe_to_replicas_change_OK",

0 commit comments

Comments
 (0)