Skip to content

Commit

Permalink
Merge pull request #12277 from hashicorp/dnephin/panic-in-service-reg…
Browse files Browse the repository at this point in the history
…ister

catalog: initialize the refs map to prevent a nil panic
  • Loading branch information
dnephin authored and hc-github-team-consul-core committed Feb 10, 2022
1 parent 8713838 commit d35c6a9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/12277.txt
@@ -0,0 +1,3 @@
```release-note:bug
config-entry: fix a panic when creating an ingress gateway config-entry and a proxy service instance, where both provided the same upstream and downstream mapping.
```
1 change: 1 addition & 0 deletions agent/consul/state/catalog.go
Expand Up @@ -3332,6 +3332,7 @@ func insertGatewayServiceTopologyMapping(tx WriteTxn, idx uint64, gs *structs.Ga
mapping := structs.UpstreamDownstream{
Upstream: gs.Service,
Downstream: gs.Gateway,
Refs: make(map[string]struct{}),
RaftIndex: gs.RaftIndex,
}
if err := tx.Insert(topologyTableName, &mapping); err != nil {
Expand Down
34 changes: 34 additions & 0 deletions agent/consul/state/catalog_test.go
Expand Up @@ -5698,6 +5698,40 @@ func setupIngressState(t *testing.T, s *Store) memdb.WatchSet {
return ws
}

func TestStore_EnsureService_DoesNotPanicOnIngressGateway(t *testing.T) {
store := NewStateStore(nil)

err := store.EnsureConfigEntry(1, &structs.IngressGatewayConfigEntry{
Kind: structs.IngressGateway,
Name: "the-ingress",
Listeners: []structs.IngressListener{
{
Port: 12345,
Protocol: "tcp",
Services: []structs.IngressService{{Name: "the-service"}},
},
},
})
require.NoError(t, err)

err = store.EnsureRegistration(2, &structs.RegisterRequest{
Node: "the-node",
Service: &structs.NodeService{
Kind: structs.ServiceKindConnectProxy,
Service: "the-proxy",
Proxy: structs.ConnectProxyConfig{
DestinationServiceName: "the-ingress",
Upstreams: []structs.Upstream{
{
DestinationName: "the-service",
},
},
},
},
})
require.NoError(t, err)
}

func TestStateStore_DumpGatewayServices(t *testing.T) {
s := testStateStore(t)

Expand Down

0 comments on commit d35c6a9

Please sign in to comment.