go-pdk
go-pdk copied to clipboard
Feature Request: Provide a `Close()` callback to clean up plugin's own resources
Currently new plugin instances are be created upon config changes and old plugin instances are removed from instances
slice so they are inaccessible and left to be garbage collected eventually. A plugin instance has no way to sense if it will not used anymore. This works fine until we have a plugin with background goroutines: our plugin starts several goroutines on start and we need them to run until the plugin instance is closed. The catch here is that we do not know if the plugin is closed, and we have no way to stop the goroutines. These goroutines hold reference to the plugin instance so nothing will be GCed.
My request is to provide a Close
callback so that the plugin instance can have a chance to clean up its own resources to prevent problems like goroutine leaks.
I can imagine that this would not be easy to implement, since the plugin instance would have to be closed after all its related events have been handled.