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