@@ -41,7 +41,9 @@ import (
4141 "github.com/containerd/containerd/runtime/linux/runctypes"
4242 "github.com/containerd/containerd/runtime/v2/runc/options"
4343 "github.com/containerd/containerd/sys"
44+
4445 "github.com/opencontainers/runtime-spec/specs-go"
46+ "github.com/stretchr/testify/require"
4547 exec "golang.org/x/sys/execabs"
4648 "golang.org/x/sys/unix"
4749)
@@ -1494,3 +1496,83 @@ func TestShimOOMScore(t *testing.T) {
14941496 case <- statusC :
14951497 }
14961498}
1499+
1500+ // TestIssue9103 is used as regression case for issue 9103.
1501+ //
1502+ // The runc-fp will kill the init process so that the shim should return stopped
1503+ // status after container.NewTask. It's used to simulate that the runc-init
1504+ // might be killed by oom-kill.
1505+ func TestIssue9103 (t * testing.T ) {
1506+ if os .Getenv ("RUNC_FLAVOR" ) == "crun" {
1507+ t .Skip ("skip it when using crun" )
1508+ }
1509+ if getRuntimeVersion () == "v1" {
1510+ t .Skip ("skip it when using shim v1" )
1511+ }
1512+
1513+ client , err := newClient (t , address )
1514+ require .NoError (t , err )
1515+ defer client .Close ()
1516+
1517+ var (
1518+ image Image
1519+ ctx , cancel = testContext (t )
1520+ id = t .Name ()
1521+ )
1522+ defer cancel ()
1523+
1524+ image , err = client .GetImage (ctx , testImage )
1525+ require .NoError (t , err )
1526+
1527+ for idx , tc := range []struct {
1528+ desc string
1529+ cntrOpts []NewContainerOpts
1530+ expectedStatus ProcessStatus
1531+ }{
1532+ {
1533+ desc : "should be created status" ,
1534+ cntrOpts : []NewContainerOpts {
1535+ WithNewSpec (oci .WithImageConfig (image ),
1536+ withProcessArgs ("sleep" , "30" ),
1537+ ),
1538+ },
1539+ expectedStatus : Created ,
1540+ },
1541+ {
1542+ desc : "should be stopped status if init has been killed" ,
1543+ cntrOpts : []NewContainerOpts {
1544+ WithNewSpec (oci .WithImageConfig (image ),
1545+ withProcessArgs ("sleep" , "30" ),
1546+ oci .WithAnnotations (map [string ]string {
1547+ "oci.runc.failpoint.profile" : "issue9103" ,
1548+ }),
1549+ ),
1550+ WithRuntime (client .Runtime (), & options.Options {
1551+ BinaryName : "runc-fp" ,
1552+ }),
1553+ },
1554+ expectedStatus : Stopped ,
1555+ },
1556+ } {
1557+ tc := tc
1558+ tName := fmt .Sprintf ("%s%d" , id , idx )
1559+ t .Run (tc .desc , func (t * testing.T ) {
1560+ container , err := client .NewContainer (ctx , tName ,
1561+ append ([]NewContainerOpts {WithNewSnapshot (tName , image )}, tc .cntrOpts ... )... ,
1562+ )
1563+ require .NoError (t , err )
1564+ defer container .Delete (ctx , WithSnapshotCleanup )
1565+
1566+ cctx , ccancel := context .WithTimeout (ctx , 30 * time .Second )
1567+ task , err := container .NewTask (cctx , empty ())
1568+ ccancel ()
1569+ require .NoError (t , err )
1570+
1571+ defer task .Delete (ctx , WithProcessKill )
1572+
1573+ status , err := task .Status (ctx )
1574+ require .NoError (t , err )
1575+ require .Equal (t , status .Status , tc .expectedStatus )
1576+ })
1577+ }
1578+ }
0 commit comments