Fix nil pointer dereference in IOInfoService.UpdateIngressState (#4806)

LoadIngress reads the ingress info and its state from two separate Redis
keys non-atomically, while DeleteIngress removes both keys in a single
transaction. If the delete lands between the two reads, LoadIngress
returns an IngressInfo with a nil State and no error, and
UpdateIngressState panics dereferencing info.State.Status — taking down
the whole server with every room it hosts.

The race fires in practice when an ingress session is being torn down by
DeleteIngress and the ingress service reports the session state change
concurrently: with short-lived per-room WHIP ingresses this crashed
production servers within minutes (observed on v1.13.5 and v1.13.6,
SIGSEGV at ioservice_ingress.go:82, addr=0x8).

Guard the nil State by treating it as an empty state, matching how the
store's UpdateIngressState already tolerates a missing state key.
This commit is contained in:
Nicolas Buszczak
2026-10-12 14:26:32 -07:00
committed by GitHub
parent 8700b35c1e
commit 3a7228fa74
2 changed files with 53 additions and 0 deletions
+7
View File
@@ -73,6 +73,13 @@ func (s *IOInfoService) UpdateIngressState(ctx context.Context, req *rpc.UpdateI
if err != nil {
return nil, err
}
if info.State == nil {
// LoadIngress reads the ingress info and its state non-atomically: a concurrent
// DeleteIngress can remove the state key between the two reads, in which case
// LoadIngress returns the info with a nil State and no error. Treat it as an
// empty state instead of panicking on the status comparison below.
info.State = &livekit.IngressState{}
}
if err = s.is.UpdateIngressState(ctx, req.IngressId, req.State); err != nil {
logger.Errorw("could not update ingress", err)
+46
View File
@@ -0,0 +1,46 @@
// Copyright 2026 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package service_test
import (
"context"
"testing"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/rpc"
"github.com/stretchr/testify/require"
"github.com/livekit/livekit-server/pkg/service"
"github.com/livekit/livekit-server/pkg/service/servicefakes"
"github.com/livekit/livekit-server/pkg/telemetry/telemetryfakes"
)
// A concurrent DeleteIngress can remove the ingress state key between the two
// non-atomic reads LoadIngress performs, making it return an IngressInfo with a
// nil State and no error. UpdateIngressState used to panic dereferencing it,
// bringing down the whole node.
func TestUpdateIngressStateWithNilState(t *testing.T) {
is := &servicefakes.FakeIngressStore{}
is.LoadIngressReturns(&livekit.IngressInfo{IngressId: "IN_test"}, nil)
io, err := service.NewIOInfoService(nil, nil, is, nil, &telemetryfakes.FakeTelemetryService{})
require.NoError(t, err)
_, err = io.UpdateIngressState(context.Background(), &rpc.UpdateIngressStateRequest{
IngressId: "IN_test",
State: &livekit.IngressState{Status: livekit.IngressState_ENDPOINT_INACTIVE},
})
require.NoError(t, err)
}