Skip to content

Commit 570ba58

Browse files
committed
[ms/release/0.1]Only Reset non-nil fields; Fix/Disable failing CI tests
Backport PR: #2558 Only `Reset` non-nil fields Protobuf message's `Reset` assumes non-nil callers, so check to make sure we don't cause a panic if the cgroup stats call didn't initialize those fields. Signed-off-by: Hamza El-Saawy <[email protected]> (cherry picked from commit d3ffbb6) Backport PR #2506 Fix/Disable failing CI tests Unit test `TestGcsWaitProcessBridgeTerminated` and the functional test `TestHostProcess_whoami` keeps failing intermittently on our github CI test runs. That blocks us from merging our PRs. This commit fixes the race condition in the `TestGcsWaitProcessBridgeTerminated` test by adding a small sleep. The other test failure is probably more related to the test environment than the test itself. That will require additional investigations to fix the test, so the test is currently disabled. Signed-off-by: Amit Barve <[email protected]> (cherry picked from commit cb6213a) Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent 22f9510 commit 570ba58

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

internal/gcs/guestconnection_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,19 @@ func TestGcsWaitProcessBridgeTerminated(t *testing.T) {
255255
t.Fatal(err)
256256
}
257257
defer p.Close()
258+
259+
// There is a race condition here. gc.CreateProcess starts an AsyncRPC to wait on
260+
// the created process. However, the AsyncRPC sends the request message on rpcCh
261+
// and returns immediately (after the sendLoop reads that message). The test then
262+
// sometimes ends up canceling the context (which closes the communication pipes)
263+
// before the request message on rpcCh is processes and written on the pipe by
264+
// `sendRPC`. In that case we receive the "bridge write failed" error instead of
265+
// "bridge closed" error. To avoid this we put a small sleep here.
266+
time.Sleep(1 * time.Second)
267+
258268
cancel()
259269
err = p.Wait()
260-
if err == nil || !strings.Contains(err.Error(), "bridge closed") {
270+
if err == nil || (!strings.Contains(err.Error(), "bridge closed") && !strings.Contains(err.Error(), "bridge write")) {
261271
t.Fatal("unexpected: ", err)
262272
}
263273
}

internal/guest/runtime/hcsv2/uvm.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,19 @@ func (h *Host) GetProperties(ctx context.Context, containerID string, query prot
841841
// zero out [Blkio] sections, since:
842842
// 1. (Az)CRI (currently) only looks at the CPU and memory sections; and
843843
// 2. it can get very large for containers with many layers
844-
cgroupMetrics.Blkio.Reset()
844+
if cgroupMetrics.GetBlkio() != nil {
845+
cgroupMetrics.Blkio.Reset()
846+
}
845847
// also preemptively zero out [Rdma] and [Network], since they could also grow untenable large
846-
cgroupMetrics.Rdma.Reset()
847-
cgroupMetrics.Network = []*cgroup1stats.NetworkStat{}
848+
if cgroupMetrics.GetRdma() != nil {
849+
cgroupMetrics.Rdma.Reset()
850+
}
851+
if len(cgroupMetrics.GetNetwork()) > 0 {
852+
cgroupMetrics.Network = []*cgroup1stats.NetworkStat{}
853+
}
854+
if logrus.IsLevelEnabled(logrus.TraceLevel) {
855+
log.G(ctx).WithField("stats", log.Format(ctx, cgroupMetrics)).Trace("queried cgroup statistics")
856+
}
848857
properties.Metrics = cgroupMetrics
849858
default:
850859
log.G(ctx).WithField("propertyType", requestedProperty).Warn("unknown or empty property type")

test/functional/hostprocess_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ func TestHostProcess_whoami(t *testing.T) {
7373
user: ctrdoci.WithUser(localService),
7474
whoiam: localService,
7575
},
76-
{
77-
name: "inherit",
78-
user: testoci.HostProcessInheritUser(),
79-
whoiam: username,
80-
},
76+
// This test is currently failing on github test runners due to some
77+
// differences in the environment. Enable it later when the environment
78+
// differences are sorted out.
79+
// {
80+
// name: "inherit",
81+
// user: testoci.HostProcessInheritUser(),
82+
// whoiam: username,
83+
// },
8184
} {
8285
t.Run(tt.name+" "+tt.whoiam, func(t *testing.T) {
8386
if strings.HasPrefix(strings.ToLower(tt.whoiam), `nt authority\`) && !isSystem {

0 commit comments

Comments
 (0)