Skip to content

Commit 3806867

Browse files
committed
Merge branch 'main' into mes/filter-work-2
2 parents d40167f + 9102256 commit 3806867

File tree

94 files changed

+3099
-623
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3099
-623
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ jobs:
186186
187187
# Check for any typos
188188
- name: Check for typos
189-
uses: crate-ci/typos@v1.24.3
189+
uses: crate-ci/typos@v1.24.5
190190
with:
191191
config: .github/workflows/typos.toml
192192

.github/workflows/contrib.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ on:
1313
- opened
1414
- reopened
1515
- edited
16+
# For jobs that don't run on draft PRs.
17+
- ready_for_review
1618

1719
# Only run one instance per PR to ensure in-order execution.
1820
concurrency: pr-${{ github.ref }}
@@ -52,7 +54,7 @@ jobs:
5254
release-labels:
5355
runs-on: ubuntu-latest
5456
# Skip tagging for draft PRs.
55-
if: ${{ github.event_name == 'pull_request_target' && success() && !github.event.pull_request.draft }}
57+
if: ${{ github.event_name == 'pull_request_target' && !github.event.pull_request.draft }}
5658
steps:
5759
- name: release-labels
5860
uses: actions/github-script@v7

agent/agent.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ func (a *agent) runCoordinator(ctx context.Context, conn drpc.Conn, network *tai
13571357
defer close(errCh)
13581358
select {
13591359
case <-ctx.Done():
1360-
err := coordination.Close()
1360+
err := coordination.Close(a.hardCtx)
13611361
if err != nil {
13621362
a.logger.Warn(ctx, "failed to close remote coordination", slog.Error(err))
13631363
}
@@ -1676,13 +1676,12 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16761676
}
16771677

16781678
score, niceErr := proc.Niceness(a.syscaller)
1679-
if niceErr != nil && !xerrors.Is(niceErr, os.ErrPermission) {
1679+
if !isBenignProcessErr(niceErr) {
16801680
debouncer.Warn(ctx, "unable to get proc niceness",
16811681
slog.F("cmd", proc.Cmd()),
16821682
slog.F("pid", proc.PID),
16831683
slog.Error(niceErr),
16841684
)
1685-
continue
16861685
}
16871686

16881687
// We only want processes that don't have a nice value set
@@ -1696,7 +1695,7 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16961695

16971696
if niceErr == nil {
16981697
err := proc.SetNiceness(a.syscaller, niceness)
1699-
if err != nil && !xerrors.Is(err, os.ErrPermission) {
1698+
if !isBenignProcessErr(err) {
17001699
debouncer.Warn(ctx, "unable to set proc niceness",
17011700
slog.F("cmd", proc.Cmd()),
17021701
slog.F("pid", proc.PID),
@@ -1710,7 +1709,7 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
17101709
if oomScore != unsetOOMScore && oomScore != proc.OOMScoreAdj && !isCustomOOMScore(agentScore, proc) {
17111710
oomScoreStr := strconv.Itoa(oomScore)
17121711
err := afero.WriteFile(a.filesystem, fmt.Sprintf("/proc/%d/oom_score_adj", proc.PID), []byte(oomScoreStr), 0o644)
1713-
if err != nil && !xerrors.Is(err, os.ErrPermission) {
1712+
if !isBenignProcessErr(err) {
17141713
debouncer.Warn(ctx, "unable to set oom_score_adj",
17151714
slog.F("cmd", proc.Cmd()),
17161715
slog.F("pid", proc.PID),
@@ -2146,3 +2145,14 @@ func (l *logDebouncer) log(ctx context.Context, level slog.Level, msg string, fi
21462145
}
21472146
l.messages[msg] = time.Now()
21482147
}
2148+
2149+
func isBenignProcessErr(err error) bool {
2150+
return err != nil &&
2151+
(xerrors.Is(err, os.ErrNotExist) ||
2152+
xerrors.Is(err, os.ErrPermission) ||
2153+
isNoSuchProcessErr(err))
2154+
}
2155+
2156+
func isNoSuchProcessErr(err error) bool {
2157+
return err != nil && strings.Contains(err.Error(), "no such process")
2158+
}

agent/agent_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,9 @@ func TestAgent_UpdatedDERP(t *testing.T) {
18961896
coordinator, conn)
18971897
t.Cleanup(func() {
18981898
t.Logf("closing coordination %s", name)
1899-
err := coordination.Close()
1899+
cctx, ccancel := context.WithTimeout(testCtx, testutil.WaitShort)
1900+
defer ccancel()
1901+
err := coordination.Close(cctx)
19001902
if err != nil {
19011903
t.Logf("error closing in-memory coordination: %s", err.Error())
19021904
}
@@ -2384,7 +2386,9 @@ func setupAgent(t *testing.T, metadata agentsdk.Manifest, ptyTimeout time.Durati
23842386
clientID, metadata.AgentID,
23852387
coordinator, conn)
23862388
t.Cleanup(func() {
2387-
err := coordination.Close()
2389+
cctx, ccancel := context.WithTimeout(testCtx, testutil.WaitShort)
2390+
defer ccancel()
2391+
err := coordination.Close(cctx)
23882392
if err != nil {
23892393
t.Logf("error closing in-mem coordination: %s", err.Error())
23902394
}

agent/agentproc/proc_unix.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ func List(fs afero.Fs, syscaller Syscaller) ([]*Process, error) {
4545

4646
cmdline, err := afero.ReadFile(fs, filepath.Join(defaultProcDir, entry, "cmdline"))
4747
if err != nil {
48-
var errNo syscall.Errno
49-
if xerrors.As(err, &errNo) && errNo == syscall.EPERM {
48+
if isBenignError(err) {
5049
continue
5150
}
5251
return nil, xerrors.Errorf("read cmdline: %w", err)
5352
}
5453

5554
oomScore, err := afero.ReadFile(fs, filepath.Join(defaultProcDir, entry, "oom_score_adj"))
5655
if err != nil {
57-
if xerrors.Is(err, os.ErrPermission) {
56+
if isBenignError(err) {
5857
continue
5958
}
6059

@@ -124,3 +123,12 @@ func (p *Process) Cmd() string {
124123
func (p *Process) cmdLine() []string {
125124
return strings.Split(p.CmdLine, "\x00")
126125
}
126+
127+
func isBenignError(err error) bool {
128+
var errno syscall.Errno
129+
if !xerrors.As(err, &errno) {
130+
return false
131+
}
132+
133+
return errno == syscall.ESRCH || errno == syscall.EPERM || xerrors.Is(err, os.ErrNotExist)
134+
}

0 commit comments

Comments
 (0)