-
Notifications
You must be signed in to change notification settings - Fork 120
APP-7995: Don't allow two module configs to point to same ExePath #4897
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,6 +343,11 @@ func (mgr *Manager) add(ctx context.Context, conf config.Module, moduleLogger lo | |
return nil | ||
} | ||
|
||
exists, existingName := mgr.execPathAlreadyExists(&conf) | ||
if exists { | ||
return errors.Errorf("An existing module %s already exists with the same executable path as module %s", existingName, conf.Name) | ||
} | ||
|
||
var moduleDataDir string | ||
// only set the module data directory if the parent dir is present (which it might not be during tests) | ||
if mgr.moduleDataParentDir != "" { | ||
|
@@ -442,6 +447,11 @@ func (mgr *Manager) Reconfigure(ctx context.Context, conf config.Module) ([]reso | |
return nil, errors.Errorf("cannot reconfigure module %s as it does not exist", conf.Name) | ||
} | ||
|
||
exists, existingName := mgr.execPathAlreadyExists(&conf) | ||
if exists { | ||
return nil, errors.Errorf("An existing module %s already exists with the same executable path as module %s", existingName, conf.Name) | ||
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. this is happening in reconfigure. thinking through the broader flow here:
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. Good question. the 2nd module will never be added to mgr.modules in add(). An error is returned during this validation before it is attempted to be started and added to mgr.modules. So in the case you brought up, module 1 will be added, module 2 will not, when module 1 is reconfigured it will pass this validation because it has no awareness that module 2 is failing to be added. 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. I also did a another round of manual testing and ensured this is the case. Didn't see this issue or anything else in the various scenarios I tested. |
||
} | ||
|
||
handledResources := mod.resources | ||
var handledResourceNames []resource.Name | ||
var handledResourceNameStrings []string | ||
|
@@ -852,6 +862,20 @@ func (mgr *Manager) getModule(conf resource.Config) (foundMod *module, exists bo | |
return | ||
} | ||
|
||
func (mgr *Manager) execPathAlreadyExists(conf *config.Module) (bool, string) { | ||
var exists bool | ||
var existingName string | ||
mgr.modules.Range(func(_ string, m *module) bool { | ||
if m.cfg.Name != conf.Name && m.cfg.ExePath == conf.ExePath { | ||
exists = true | ||
existingName = m.cfg.Name | ||
return false | ||
} | ||
return true | ||
}) | ||
return exists, existingName | ||
} | ||
|
||
// CleanModuleDataDirectory removes unexpected folders and files from the robot's module data directory. | ||
// Modules removed from the robot config (even temporarily) will get pruned here. | ||
func (mgr *Manager) CleanModuleDataDirectory() error { | ||
|
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.
does this break the entire reconfigure? or does the reconfigure loop continue for other modules
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.
It will only stop reconfigure for this module. The reconfigure loop is higher up in the stack, this method is called for each module in the case where there are multiple modules being reconfigured.
So this one module would error, and the existing module that is already configured with the same exepath will keep running.