Skip to content

Commit e6793a0

Browse files
committed
fix: limit no data in fd log messages
1 parent 65fded1 commit e6793a0

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages/orchestrator/internal/sandbox/uffd/userfaultfd/eagain.go renamed to packages/orchestrator/internal/sandbox/uffd/userfaultfd/counter_reporter.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
1010
)
1111

12-
type eagainCounter struct {
12+
type counterReporter struct {
1313
count uint64
1414
startTime time.Time
1515
endTime time.Time
1616
logger logger.Logger
1717
msg string
1818
}
1919

20-
func newEagainCounter(logger logger.Logger, msg string) *eagainCounter {
21-
return &eagainCounter{
20+
func newCounterReporter(logger logger.Logger, msg string) *counterReporter {
21+
return &counterReporter{
2222
count: 0,
2323
startTime: time.Time{},
2424
endTime: time.Time{},
@@ -27,7 +27,7 @@ func newEagainCounter(logger logger.Logger, msg string) *eagainCounter {
2727
}
2828
}
2929

30-
func (c *eagainCounter) Increase() {
30+
func (c *counterReporter) Increase() {
3131
if c.count == 0 {
3232
c.startTime = time.Now()
3333
}
@@ -37,7 +37,7 @@ func (c *eagainCounter) Increase() {
3737
c.endTime = time.Now()
3838
}
3939

40-
func (c *eagainCounter) log(ctx context.Context, closing bool) {
40+
func (c *counterReporter) log(ctx context.Context, closing bool) {
4141
if c.count > 0 {
4242
c.logger.Debug(ctx,
4343
c.msg,
@@ -51,10 +51,10 @@ func (c *eagainCounter) log(ctx context.Context, closing bool) {
5151
}
5252
}
5353

54-
func (c *eagainCounter) Close(ctx context.Context) {
54+
func (c *counterReporter) Close(ctx context.Context) {
5555
c.log(ctx, true)
5656
}
5757

58-
func (c *eagainCounter) Log(ctx context.Context) {
58+
func (c *counterReporter) Log(ctx context.Context) {
5959
c.log(ctx, false)
6060
}

packages/orchestrator/internal/sandbox/uffd/userfaultfd/userfaultfd.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ func (u *Userfaultfd) Serve(
8686
{Fd: fdExit.Reader(), Events: unix.POLLIN},
8787
}
8888

89-
eagainCounter := newEagainCounter(u.logger, "uffd: eagain during fd read (accumulated)")
89+
eagainCounter := newCounterReporter(u.logger, "uffd: eagain during fd read (accumulated)")
9090
defer eagainCounter.Close(ctx)
9191

92+
noDataCounter := newCounterReporter(u.logger, "uffd: no data in fd (accumulated)")
93+
defer noDataCounter.Close(ctx)
94+
9295
outerLoop:
9396
for {
9497
if _, err := unix.Poll(
@@ -135,7 +138,7 @@ outerLoop:
135138
// - https://man7.org/linux/man-pages/man2/userfaultfd.2.html
136139
// It might be possible to just check for data != 0 in the syscall.Read loop
137140
// but I don't feel confident about doing that.
138-
u.logger.Debug(ctx, "uffd: no data in fd, going back to polling")
141+
noDataCounter.Increase()
139142

140143
continue
141144
}
@@ -154,6 +157,7 @@ outerLoop:
154157
// There is no error so we can proceed.
155158

156159
eagainCounter.Log(ctx)
160+
noDataCounter.Log(ctx)
157161

158162
break
159163
}

0 commit comments

Comments
 (0)