Skip to content

Comments

Update deprecated systemddbus#4434

Merged
dustymabe merged 1 commit intocoreos:mainfrom
angelcerveraroldan:update-deprecated-systemddbus
Feb 23, 2026
Merged

Update deprecated systemddbus#4434
dustymabe merged 1 commit intocoreos:mainfrom
angelcerveraroldan:update-deprecated-systemddbus

Conversation

@angelcerveraroldan
Copy link
Contributor

@angelcerveraroldan angelcerveraroldan commented Feb 11, 2026

Update kola.go to use sdconn.SubscribeUnitsCustomContext instead of sdconn.SubscribeUnitsCustom since its deprecated.

This should fix the following error in golangci-lint:

Error: SA1019: sdconn.SubscribeUnitsCustom is deprecated: use SubscribeUnitsCustomContext instead.  (staticcheck)

Closes #4436

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the go-systemd dependency to version v22.7.0 and replaces the deprecated sdconn.SubscribeUnitsCustom function with the context-aware sdconn.SubscribeUnitsCustomContext in mantle/cmd/kolet/kolet.go. The change correctly passes a context to the new function.

However, the introduction of a context-aware subscription function means the returned channels can now be closed upon context cancellation. The existing code does not handle this, which could lead to a busy-loop. I've added a comment with a suggestion to make the code more robust by handling channel closures.

The rest of the changes are in vendored files and are part of the dependency update. They include several improvements like adding context support across the API, refactoring with generics, and making data structures thread-safe, which are all positive changes.

}
compareFunc := func(u1, u2 *systemddbus.UnitStatus) bool { return *u1 != *u2 }
unitevents, uniterrs := sdconn.SubscribeUnitsCustom(time.Second, 0, compareFunc, filterFunc)
unitevents, uniterrs := sdconn.SubscribeUnitsCustomContext(ctx, time.Second, 0, compareFunc, filterFunc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While context.Background() is used here, which never gets canceled, switching to SubscribeUnitsCustomContext introduces the possibility for the returned unitevents and uniterrs channels to be closed if a cancellable context is used in the future.

The select loop starting on line 410 does not check if the channels are closed. Reading from a closed channel returns a zero value immediately without blocking. This would cause a busy-loop, consuming 100% CPU.

To make the code more robust and prevent this potential issue, you should check for channel closure in the select statement.

For example:

// in the for loop
select {
// ... other cases
case m, ok := <-unitevents:
    if !ok {
        systemdjournal.Print(systemdjournal.PriInfo, "unitevents channel closed")
        return nil
    }
    // ... existing logic for unitevents
case err, ok := <-uniterrs:
    if !ok {
        systemdjournal.Print(systemdjournal.PriInfo, "uniterrs channel closed")
        return nil
    }
    return err
// ... other cases
}

@angelcerveraroldan angelcerveraroldan added jira for syncing to jira and removed jira for syncing to jira labels Feb 12, 2026
@Rolv-Apneseth
Copy link
Contributor

/retest

@dustymabe
Copy link
Member

code LGTM, but the commit titles and messages need a little more (as requested similarly over in #4438 (comment)).

The context in the description of the PR here would be good to add to the second commit commit message.

@angelcerveraroldan angelcerveraroldan force-pushed the update-deprecated-systemddbus branch from c1068ee to 53fc7c4 Compare February 18, 2026 10:03
@prestist
Copy link
Contributor

Same comment as here #4438 (comment)

@angelcerveraroldan angelcerveraroldan force-pushed the update-deprecated-systemddbus branch from 53fc7c4 to eb0cafe Compare February 19, 2026 17:07
@prestist
Copy link
Contributor

prestist commented Feb 19, 2026

Ah lets remove the '`' as it does some odd formatting from the perspective viewing it. otherwise lgtm

i.e systemddbus: go-systemd/v22/dbus deprecated function => systemddbus: replace go-systemd/v22/dbus deprecated function

Update systemd-go library

```
got get github.com/coreos/go-systemd/v22/dbus@latest
go mod vendor
go mod tidy
```

And replace sdconn.SubscribeUnitsCustom with
sdconn.SubscribeUnitsCustomContext in kolet.go

This fixes the following error:

SA1019: sdconn.SubscribeUnitsCustom is deprecated:
use SubscribeUnitsCustomContext instead.  (staticcheck)
@angelcerveraroldan angelcerveraroldan force-pushed the update-deprecated-systemddbus branch from eb0cafe to 8c83f8c Compare February 23, 2026 10:09
Copy link
Contributor

@prestist prestist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for working on this @angelcerveraroldan!

Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dustymabe dustymabe merged commit 8a2c225 into coreos:main Feb 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linter failing with sdconn.SubscribeUnitsCustom is deprecated: use SubscribeUnitsCustomContext instead

4 participants