fix(relay/client):error handling for rpc's and replacing errgroup with sync.WaitGroup #55
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.
Refactors the
connectToKubeArmor
function to replace the usage oferrgroup.Group
withsync.WaitGroup
for managing goroutines and introduces a mechanism to stop all goroutines if any one of them encounters an error.Introduced a shared
stop
channel to signal all goroutines to stop if any one of them encounters an error.Added a buffered
errCh
channel to propagate errors from the goroutines back to theconnectToKubeArmor
function.Implemented error propagation within each watcher function. If a goroutine encounters an error, it sends the error to
errCh
and returns.Updated
connectToKubeArmor
to listen for errors onerrCh
and to close thestop
channel to signal all goroutines to stop if an error occurs.Ensured that it waits for all goroutines to finish before proceeding with client destruction if no error is found.
Tested manually by scheduling an error. After the error hit, the other goroutines will end and new connection will be made with the rpc's. Also checked logs and alerts after error, they are working as expected.
Logs, shows reconnection happens: