@@ -28,6 +28,7 @@ import (
2828 "strconv"
2929 "strings"
3030 "sync"
31+ "sync/atomic"
3132 "testing"
3233 "time"
3334
@@ -3710,3 +3711,39 @@ func TestUnsupportedServerConfigOptions(t *testing.T) {
37103711 })
37113712 }
37123713}
3714+
3715+ func TestGetConfigAfterFailToStartOnlineProcess (t * testing.T ) {
3716+ rt := NewRestTester (t , & RestTesterConfig {
3717+ PersistentConfig : true ,
3718+ })
3719+ defer rt .Close ()
3720+
3721+ dbConfig := rt .NewDbConfig ()
3722+ dbConfig .StartOffline = base .Ptr (true )
3723+ resp := rt .CreateDatabase ("db" , dbConfig )
3724+ RequireStatus (t , resp , http .StatusCreated )
3725+
3726+ // create invalid user to cause StartOnlineProcesses error
3727+ rt .GetDatabase ().Options .ConfigPrincipals .Users = map [string ]* auth.PrincipalConfig {
3728+ "alice" : {
3729+ JWTChannels : base .SetOf ("asdf" ),
3730+ },
3731+ }
3732+
3733+ // Directly set the database state to DBStarting to simulate regular startup.
3734+ // This direct atomic manipulation is required in this test to simulate a state transition.
3735+ // This is safe in the context of this test.
3736+ atomic .StoreUint32 (& rt .GetDatabase ().State , db .DBStarting )
3737+ rt .WaitForDBState (db .RunStateString [db .DBStarting ])
3738+
3739+ // Can't trigger error case from REST API - call directly
3740+ rt .ServerContext ().asyncDatabaseOnline (base .NewNonCancelCtx (), rt .GetDatabase (), nil , rt .ServerContext ().GetDbVersion ("db" ))
3741+
3742+ // Error should cause db to stay offline.
3743+ rt .WaitForDBState (db .RunStateString [db .DBOffline ])
3744+ require .Equal (t , int64 (1 ), rt .GetDatabase ().DbStats .Database ().TotalOnlineFatalErrors .Value ())
3745+
3746+ // Original bug will trigger panic here on this endpoint
3747+ resp = rt .SendAdminRequest (http .MethodGet , "/_config?include_runtime=true" , "" )
3748+ RequireStatus (t , resp , http .StatusOK )
3749+ }
0 commit comments