-
Notifications
You must be signed in to change notification settings - Fork 109
fix: fix some modules loaded failed #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
dde-session-daemon part2 load after org.deepin.dde.SessionManager1 running Log: pms: BUG-323803
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @fly602 - I've reviewed your changes - here's some feedback:
- You’re ignoring the error from dbus.SessionBus()—make sure to handle or log it before using sessionBus to avoid nil-pointer issues.
- The signal loop started via sessionSigLoop.Start() is never stopped—add proper cleanup (e.g. sessionSigLoop.Stop()) after removing the handler to prevent resource leaks.
- Dropping the DDE_SESSION_PROCESS_COOKIE_ID check in StartPart2 may introduce unexpected states—verify that removing this validation is safe for all launch scenarios.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You’re ignoring the error from dbus.SessionBus()—make sure to handle or log it before using sessionBus to avoid nil-pointer issues.
- The signal loop started via sessionSigLoop.Start() is never stopped—add proper cleanup (e.g. sessionSigLoop.Stop()) after removing the handler to prevent resource leaks.
- Dropping the DDE_SESSION_PROCESS_COOKIE_ID check in StartPart2 may introduce unexpected states—verify that removing this validation is safe for all launch scenarios.
## Individual Comments
### Comment 1
<location> `bin/dde-session-daemon/daemon.go:255` </location>
<code_context>
- } else {
- err = loader.EnableModules(s.getAllDefaultEnabledModules(),
- s.getAllDefaultDisabledModules(), getEnableFlag(s.flags))
+ err = loader.EnableModules(s.part1EnabledModules, s.part1DisabledModules, 0)
+ if err != nil {
+ logger.Warning("Failed to enable part1 modules:", err)
</code_context>
<issue_to_address>
Consider extracting the DBus and signal loop logic from execDefaultAction into a dedicated helper to keep the function focused and readable.
```suggestion
The new DBus/signal‐loop logic in `execDefaultAction` is adding a lot of noise. You can pull it into a small helper (e.g. `sessionWatcher`) and keep `execDefaultAction` focused:
--- session_watcher.go ---
```go
package main
import (
"sync"
"github.com/godbus/dbus/v5"
dbusmgr "github.com/linuxdeepin/go-dbus-factory/system/org.freedesktop.dbus"
"github.com/linuxdeepin/go-lib/dbusutil"
)
type sessionWatcher struct {
once sync.Once
mgr *dbusmgr.DBus
loop *dbusutil.SignalLoop
}
func newSessionWatcher(conn *dbus.Conn) *sessionWatcher {
loop := dbusutil.NewSignalLoop(conn, 10)
loop.Start()
mgr := dbusmgr.NewDBus(conn)
mgr.InitSignalExt(loop, true)
return &sessionWatcher{mgr: mgr, loop: loop}
}
// Start invokes `onStarted` once when the name appears (or already exists).
func (w *sessionWatcher) Start(onStarted func()) error {
handler, err := w.mgr.ConnectNameOwnerChanged(func(name, _, newOwner string) {
if name == "org.deepin.dde.SessionManager1" && newOwner != "" {
w.once.Do(func() {
onStarted()
w.mgr.RemoveHandler(handler)
})
}
})
if err != nil {
return err
}
ok, err := w.mgr.NameHasOwner(0, "org.deepin.dde.SessionManager1")
if err != nil {
return err
}
if ok {
w.once.Do(func() {
onStarted()
w.mgr.RemoveHandler(handler)
})
}
return nil
}
```
Then simplify `execDefaultAction`:
```go
func (s *SessionDaemon) execDefaultAction() {
if err := loader.EnableModules(s.part1EnabledModules, s.part1DisabledModules, 0); err != nil {
logger.Warning("Failed to enable part1 modules:", err)
os.Exit(3)
}
conn, _ := dbus.SessionBus()
watcher := newSessionWatcher(conn)
if err := watcher.Start(s.StartPart2); err != nil {
logger.Warning("session watcher setup failed:", err)
os.Exit(3)
}
}
```
This keeps all functionality, reduces nesting in `execDefaultAction`, and moves DBus details into a focused helper.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| } else { | ||
| err = loader.EnableModules(s.getAllDefaultEnabledModules(), | ||
| s.getAllDefaultDisabledModules(), getEnableFlag(s.flags)) | ||
| err = loader.EnableModules(s.part1EnabledModules, s.part1DisabledModules, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider extracting the DBus and signal loop logic from execDefaultAction into a dedicated helper to keep the function focused and readable.
| err = loader.EnableModules(s.part1EnabledModules, s.part1DisabledModules, 0) | |
| The new DBus/signal‐loop logic in `execDefaultAction` is adding a lot of noise. You can pull it into a small helper (e.g. `sessionWatcher`) and keep `execDefaultAction` focused: | |
| --- session_watcher.go --- | |
| ```go | |
| package main | |
| import ( | |
| "sync" | |
| "github.com/godbus/dbus/v5" | |
| dbusmgr "github.com/linuxdeepin/go-dbus-factory/system/org.freedesktop.dbus" | |
| "github.com/linuxdeepin/go-lib/dbusutil" | |
| ) | |
| type sessionWatcher struct { | |
| once sync.Once | |
| mgr *dbusmgr.DBus | |
| loop *dbusutil.SignalLoop | |
| } | |
| func newSessionWatcher(conn *dbus.Conn) *sessionWatcher { | |
| loop := dbusutil.NewSignalLoop(conn, 10) | |
| loop.Start() | |
| mgr := dbusmgr.NewDBus(conn) | |
| mgr.InitSignalExt(loop, true) | |
| return &sessionWatcher{mgr: mgr, loop: loop} | |
| } | |
| // Start invokes `onStarted` once when the name appears (or already exists). | |
| func (w *sessionWatcher) Start(onStarted func()) error { | |
| handler, err := w.mgr.ConnectNameOwnerChanged(func(name, _, newOwner string) { | |
| if name == "org.deepin.dde.SessionManager1" && newOwner != "" { | |
| w.once.Do(func() { | |
| onStarted() | |
| w.mgr.RemoveHandler(handler) | |
| }) | |
| } | |
| }) | |
| if err != nil { | |
| return err | |
| } | |
| ok, err := w.mgr.NameHasOwner(0, "org.deepin.dde.SessionManager1") | |
| if err != nil { | |
| return err | |
| } | |
| if ok { | |
| w.once.Do(func() { | |
| onStarted() | |
| w.mgr.RemoveHandler(handler) | |
| }) | |
| } | |
| return nil | |
| } |
Then simplify execDefaultAction:
func (s *SessionDaemon) execDefaultAction() {
if err := loader.EnableModules(s.part1EnabledModules, s.part1DisabledModules, 0); err != nil {
logger.Warning("Failed to enable part1 modules:", err)
os.Exit(3)
}
conn, _ := dbus.SessionBus()
watcher := newSessionWatcher(conn)
if err := watcher.Start(s.StartPart2); err != nil {
logger.Warning("session watcher setup failed:", err)
os.Exit(3)
}
}This keeps all functionality, reduces nesting in execDefaultAction, and moves DBus details into a focused helper.
Reviewer's GuideUnify the session daemon startup by removing the cookie-based gating, always enabling part1 modules with robust error handling, and implementing a DBus-based signal listener (with immediate owner check) to trigger part2 when the SessionManager is available. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
TAG Bot New tag: 6.1.43 |
deepin pr auto review关键摘要:
是否建议立即修改: |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, robertkill The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
dde-session-daemon part2 load after org.deepin.dde.SessionManager1 running
Log:
pms: BUG-323803
Summary by Sourcery
Defer part2 module initialization until the DDE SessionManager1 D-Bus service is available, remove the outdated cookie check, and add robust error handling for part1 module loading.
Bug Fixes:
Enhancements: