fix(filter): Fixed multiple connections closing in Moira-Filter caused by PR-562. #570
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.
Fixed multiple connections closing in Moira Filter when closing one of the tcp connection.
PR Summary
A go-routine leak was fixed in PR-562, but it caused closing multiple connections when any of them were close. I guess that this is because a channel named handler.terminate is common to all goroutines, spawned in any instance of the handle function. When any data send to this channel, several goroutines receive them and closing their connection.
This PR suggests using an extra computation using the channel, named closeConnection to handle goroutine completion instead simple send any data into handler.terminate. This channel is local to each call to the handle function and the goroutine it spawns. Thus, when one connection will be closed, the goroutine, associated with the specific call to the handle function will complete and others continue work. Watching for closeConnection channel implemented via select block.
Additional information
Closes/Relates #issue