go-pdk icon indicating copy to clipboard operation
go-pdk copied to clipboard

Feature Request: Provide a `Close()` callback to clean up plugin's own resources

Open raptium opened this issue 2 years ago • 0 comments

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.

raptium avatar May 04 '22 01:05 raptium