Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relay-server: handle channels gracefully #16

Merged
merged 1 commit into from
Mar 10, 2022

Conversation

daemon1024
Copy link
Member

@daemon1024 daemon1024 commented Mar 9, 2022

  • use select for non-blocking channel operations instead of goroutines, noting this will skip sending the log if channel is blocked for some reason https://gobyexample.com/non-blocking-channel-operations
  • bring back Map Structure Lock to prevent data races, we removed the lock because channel handing was blocking which caused issues but was not the right way to proceed.
  • close channel after deleting client to prevent memory leaks

Ref #15

- use select for non-blocking channel operations instead of goroutines, noting this will skip sending the log if channel is blocked for some reason
- bring back Structure Lock to prevent data races
- close channel after deleting client to prevent memory leaks

Signed-off-by: daemon1024 <[email protected]>
@daemon1024 daemon1024 requested a review from nyrahul March 9, 2022 14:45
Copy link
Contributor

@nyrahul nyrahul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary fix seems to be that of closing the connection.
I see that the locks have returned. Is the point that now that we close the connection, the log sent to broadcast channel would fail (and not get stuck) since we are closing the connection?

@daemon1024
Copy link
Member Author

daemon1024 commented Mar 10, 2022

@nyrahul the primary fix here is usage of select. Select chooses the non blocking cases, if our channel is blocking it will choose the default case and move on to next iteration.

Closing the channel is just a safety measure to prevent memory leaks since after deleting the client from our map structure, the channel pointer would dangle waiting to be garbage collected.

@nyrahul
Copy link
Contributor

nyrahul commented Mar 10, 2022

Tested the PR. This fixes #15

@nyrahul nyrahul merged commit 01b1eec into kubearmor:main Mar 10, 2022
daemon1024 added a commit to daemon1024/KubeArmor that referenced this pull request Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants