-
Notifications
You must be signed in to change notification settings - Fork 126
RSDK-12103: Add failing modules to error for failed API Model #5461
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
Open
allisonschiang
wants to merge
21
commits into
viamrobotics:main
Choose a base branch
from
allisonschiang:RSDK-12103
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1ac835e
init
allisonschiang 84dc653
Update manager.go
allisonschiang 9b2abf9
lint
allisonschiang f1dba6b
test
allisonschiang db908c9
init
allisonschiang 911bf3f
upda
allisonschiang 92073fc
update
allisonschiang a2a6bce
Update manager_test.go
allisonschiang d19e8f8
Update resource_manager_modular_test.go
allisonschiang 90f2e96
update tests
allisonschiang ab084eb
lint
allisonschiang 00f9899
changes
allisonschiang f5acc5f
Update module_lifecycle_test.go
allisonschiang a8551d8
update
allisonschiang 9b3ca14
add log filter
allisonschiang 0af4a5c
changes
allisonschiang b5fd88a
updates
allisonschiang d8db333
lint?
allisonschiang 1c5b525
Update manager.go
allisonschiang f1691a0
Update module_lifecycle_test.go
allisonschiang 27202e2
Merge branch 'viamrobotics:main' into RSDK-12103
allisonschiang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,7 @@ func NewManager( | |
| packagesDir: options.PackagesDir, | ||
| ftdc: options.FTDC, | ||
| modPeerConnTracker: options.ModPeerConnTracker, | ||
| failedModules: make(map[string]bool), | ||
| } | ||
| return ret, nil | ||
| } | ||
|
|
@@ -151,6 +152,9 @@ type Manager struct { | |
| // modPeerConnTracker must be updated as modules create/destroy any underlying WebRTC | ||
| // PeerConnections. | ||
| modPeerConnTracker *rdkgrpc.ModPeerConnTracker | ||
|
|
||
| failedModulesMu sync.RWMutex | ||
| failedModules map[string]bool | ||
| } | ||
|
|
||
| // Close terminates module connections and processes. | ||
|
|
@@ -256,6 +260,7 @@ func (mgr *Manager) Add(ctx context.Context, confs ...config.Module) error { | |
| // The config was already validated, but we must check again before attempting to add. | ||
| if err := conf.Validate(""); err != nil { | ||
| mgr.logger.CErrorw(ctx, "Module config validation error; skipping", "module", conf.Name, "error", err) | ||
| mgr.AddToFailedModules(conf.Name) | ||
| errs[i] = err | ||
| continue | ||
| } | ||
|
|
@@ -270,9 +275,12 @@ func (mgr *Manager) Add(ctx context.Context, confs ...config.Module) error { | |
| err := mgr.add(ctx, conf, moduleLogger) | ||
| if err != nil { | ||
| moduleLogger.CErrorw(ctx, "Error adding module", "module", conf.Name, "error", err) | ||
| mgr.AddToFailedModules(conf.Name) | ||
| errs[i] = err | ||
| return | ||
| } | ||
| // module started successfully, remove it from failedModules | ||
| mgr.deleteFromFailedModules(conf.Name) | ||
| }(i, conf) | ||
| } | ||
| wg.Wait() | ||
|
|
@@ -428,10 +436,15 @@ func (mgr *Manager) Reconfigure(ctx context.Context, conf config.Module) ([]reso | |
| mod.logger.CInfow(ctx, "Existing module process stopped. Starting new module process", "module", conf.Name) | ||
|
|
||
| if err := mgr.startModule(ctx, mod); err != nil { | ||
| // could not start module during reconfiguration, add it to failedModules | ||
| mgr.AddToFailedModules(conf.Name) | ||
| // If re-addition fails, assume all handled resources are orphaned. | ||
| return handledResourceNames, err | ||
| } | ||
|
|
||
| // reconfiguration successful, remove from failed modules | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if reconfig successful (module gets fixed? or something breaking the module gets fixed) remove from failedModules |
||
| mgr.deleteFromFailedModules(conf.Name) | ||
|
|
||
| mod.logger.CInfow(ctx, "New module process is running and responding to gRPC requests", "module", | ||
| mod.cfg.Name, "module address", mod.addr) | ||
|
|
||
|
|
@@ -847,6 +860,9 @@ func (mgr *Manager) newOnUnexpectedExitHandler(ctx context.Context, mod *module) | |
| "Module has unexpectedly exited.", "module", mod.cfg.Name, "exit_code", exitCode, | ||
| ) | ||
|
|
||
| // Add to failedModules when crash is detected | ||
| mgr.AddToFailedModules(mod.cfg.Name) | ||
|
|
||
| // There are two relevant calls that may race with a crashing module: | ||
| // 1. mgr.Remove, which wants to stop the module and remove it entirely | ||
| // 2. mgr.Reconfigure, which wants to stop the module and replace it with | ||
|
|
@@ -899,8 +915,12 @@ func (mgr *Manager) newOnUnexpectedExitHandler(ctx context.Context, mod *module) | |
|
|
||
| err := mgr.attemptRestart(ctx, mod) | ||
| if err == nil { | ||
| // restart successful, remove module from failedModules | ||
| mgr.deleteFromFailedModules(mod.cfg.Name) | ||
| break | ||
| } | ||
| // could not restart crashed module, add it to failedModules | ||
| mgr.AddToFailedModules(mod.cfg.Name) | ||
| unlock() | ||
| utils.SelectContextOrWait(ctx, oueRestartInterval) | ||
| } | ||
|
|
@@ -1120,3 +1140,38 @@ func getModuleDataParentDirectory(options modmanageroptions.Options) string { | |
| } | ||
| return filepath.Join(options.ViamHomeDir, parentModuleDataFolderName, robotID) | ||
| } | ||
|
|
||
| // AddToFailedModules adds a failing module to the failedModules map. | ||
| func (mgr *Manager) AddToFailedModules(moduleName string) { | ||
| mgr.failedModulesMu.Lock() | ||
| mgr.failedModules[moduleName] = true | ||
| mgr.failedModulesMu.Unlock() | ||
| } | ||
|
|
||
| func (mgr *Manager) deleteFromFailedModules(moduleName string) { | ||
| mgr.failedModulesMu.Lock() | ||
| delete(mgr.failedModules, moduleName) | ||
| mgr.failedModulesMu.Unlock() | ||
| } | ||
|
|
||
| // FailedModules returns the names of all failing modules. | ||
| func (mgr *Manager) FailedModules() []string { | ||
allisonschiang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mgr.failedModulesMu.RLock() | ||
| defer mgr.failedModulesMu.RUnlock() | ||
| var failedModuleNames []string | ||
| for moduleName := range mgr.failedModules { | ||
| failedModuleNames = append(failedModuleNames, moduleName) | ||
| } | ||
| return failedModuleNames | ||
| } | ||
|
|
||
| // UpdateFailedModules clears the failedModules map at the start of reconfigure. | ||
| // Modules will be added to failedModules as they fail during the reconfigure process. | ||
| func (mgr *Manager) UpdateFailedModules(newConfigModules []config.Module) { | ||
allisonschiang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mgr.failedModulesMu.Lock() | ||
| defer mgr.failedModulesMu.Unlock() | ||
|
|
||
| for k := range mgr.failedModules { | ||
| delete(mgr.failedModules, k) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.