These issues occur, because the channel is closed before all goroutines have a chance to complete. In order to avoid that, add a Wait() on each WaitGroup to block until goroutines complete.
In order to maximize parallel execution prior to blocking, initialize all WaitGroups in system_collector prior to walking the System tree. Then, block with Wait() directives after all goroutines are executed. The down side to this approach is that some WaitGroups may be created for resources that aren't present on a given system. However, I believe it's worth it for the parallel execution.
I have been running a local version like this on my fleet for months on 1000s of servers without issue and haven't seen a panic: send on closed channel since.
This PR seeks to fix issues like the following:
See https://github.com/jenningsloy318/redfish_exporter/issues/64 for examples of others who have encountered the same problem.
These issues occur, because the channel is closed before all
goroutines
have a chance to complete. In order to avoid that, add aWait()
on eachWaitGroup
to block untilgoroutines
complete.In order to maximize parallel execution prior to blocking, initialize all
WaitGroups
insystem_collector
prior to walking theSystem
tree. Then, block withWait()
directives after allgoroutines
are executed. The down side to this approach is that someWaitGroups
may be created for resources that aren't present on a given system. However, I believe it's worth it for the parallel execution.I have been running a local version like this on my fleet for months on 1000s of servers without issue and haven't seen a
panic: send on closed channel
since.