Comments (4)
Thanks for the report.
It would be good to pinpoint where that error is being generated.
I think this may be coming from the underlying go-dbus, possibly by some methods not properly context-aware.
My raw guess is that is failing at some point during the Hello
or Auth
steps for dbus.
from go-systemd.
Hi @lucab, thanks for the reply. I just took a quick look with a debugger
The NewSystemConnectionContext calls
// 1
func NewSystemConnectionContext(ctx context.Context) (*Conn, error) {
return NewConnection(func() (*dbus.Conn, error) {
return dbusAuthHelloConnection(ctx, dbus.SystemBusPrivate)
})
}
// 2
func NewConnection(dialBus func() (*dbus.Conn, error)) (*Conn, error) {
sysconn, err := dialBus()
// so the go anonymous function gets called
func dbusAuthHelloConnection(ctx context.Context, createBus func(opts ...dbus.ConnOption) (*dbus.Conn, error)) (*dbus.Conn, error) {
conn, err := dbusAuthConnection(ctx, createBus)
// which in terms calls the go-dbus SystemBusPrivate method with conniption dbus with Context
conn, err := createBus(dbus.WithContext(ctx))
if err != nil {
return nil, err
}
Development Error 1 - go-dbus
Without checking context expiry the package just returned a new connection (image above) without any error.
Development Error 2 - go-dbus
The newConn
function from go-dbus
runs a watcher in a goroutine. While monitoring the context, upon ctx.Done()
event they just abruptly closed the underlying connection without throwing/caching the actual error.
Now all subsequent requests to the conn fail (as the connection is already closed). But the reason for closing the connection was never revealed.
ref:
https://github.com/godbus/dbus/blob/b357b44b7ab3bf9e9b27c906fb31cb622b7a017e/conn.go#L302-L306
Now I think we have two options:
- Not use the
dbus.WithContext(ctx)
as a connection option and implement our own watcher. It's not very complicated. I can help you with that.
one example: https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/tast-tests/src/chromiumos/tast/common/testexec/testexec.go (a context-aware exec)
As go-dbus is very good at providing the primitives (I think it should keep doing it that way instead of worrying about everything) but developers mostly care for the ready to use methods that go-systemd/dbus provides unless they are writing a dbus package. (we can tell them to remove dbus.WithContext(ctx)
as it doesn't work as expected).
- Make the changes in the go-dbus codebase.
Do let me know what you think. Thanks!
from go-systemd.
ping @lucab
from go-systemd.
It sounds like you have pinpointed some faulty logic in go-dbus
, so I'd suggest taking this discussion there and try to enhance that code. I'm not really keen on trying to add dbus workarounds here as they always increase maintenance complexity, no matter how simple they seem.
That said, I also fear that you may be chasing a ghost.
Context expiration happens asynchronously, so there is always going to be an implicit race between the context watcher (which closes the connection) and other I/O methods (which use the connection).
Even after improving the logic which creates a connection, I think you will always face this race later on (e.g. when using a very small but non-zero timeout). Depending on the non-deterministic result of this race, you may keep seeing I/O errors being returned when the connection gets closed.
from go-systemd.
Related Issues (20)
- Why is this error "dbus: connection closed by user"
- Invalid ExecStart command created using PropExecStart
- Module for reading service credentials HOT 1
- Writing `UNIT` to journal HOT 1
- Socket activation logic lacks error checking
- Different test failure results when build and tested on 1)ppc64le arch with rhel image and 2)ppc64le arch without image HOT 1
- sdjournal: please add support for journal namespaces HOT 2
- No asynchronous response when service is stopped HOT 3
- "Process org.freedesktop.systemd1 exited with status 1" when using GetUnitPropertiesContext HOT 1
- Is it possible to interact with systemd system units as non-root user? (Authentication?)
- Fail sdjournal on armhf architecture
- StartUnitContext did not respect context in matter of the jobComplete signal
- Cannot Start or Stop Units anymore, when nothing reads from the job completion channel
- help: Cannot set property ExecStopPost, or unknown property. HOT 1
- dbus properties are missing the `Environment` key.
- Managing a "user unit file" via dbus, how?
- slog handler for writing into journal HOT 2
- Support hostname1 D-Bus interface HOT 1
- Feature request: support fdstore functionality
- cpuset disappears from /sys/fs/cgroup/cgroup.subtree_control after adding it HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-systemd.