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

Fix goroutine leak #1015

Merged
merged 2 commits into from
Nov 6, 2024
Merged

Fix goroutine leak #1015

merged 2 commits into from
Nov 6, 2024

Conversation

evrardjp
Copy link
Collaborator

@evrardjp evrardjp commented Nov 5, 2024

Without this patch, we use WriterLevel, which spawns go routines. As we do it at every call of the util commands, we spawn goroutines at every check.

This is a problem as it leads to memory management issues.

This fixes it by using a buffer for stdout and stderr, then logging the results after the command was executed.

To make sure the logging happened at the same place, I inlined the code from utils. This results in duplicated the code.

However, this is not a big problem as:

  • It makes the code more readable
  • The implementation between checkers and rebooters ARE different -- One definitely NEEDS privileges, while the other does not... Which could lead to later improvements.

Removing a "utils" package is not really a big deal (it is kinda a win in itself, as it is an anti-pattern), as the test coverage was kept.

Partial-Fix: #1004
Fixes: #1013

Without this patch, we use WriterLevel, which spawns
go routines. As we do it at every call of the util commands,
we spawn goroutines at every check.

This is a problem as it leads to memory management issues.

This fixes it by using a buffer for stdout and stderr, then
logging the results after the command was executed.

To make sure the logging happened at the same place, I inlined
the code from utils. This results in duplicated the code.

However, this is not a big problem as:
- It makes the code more readable
- The implementation between checkers and rebooters _ARE_
  different -- One definitely NEEDS privileges, while the other
  does not... Which could lead to later improvements.

Removing a "utils" package is not really a big deal (it
is kinda a win in itself, as it is an anti-pattern), as the
test coverage was kept.

Partial-Fix: kubereboot#1004
Fixes: kubereboot#1013
Signed-off-by: Jean-Philippe Evrard <[email protected]>
@evrardjp
Copy link
Collaborator Author

evrardjp commented Nov 5, 2024

@jonaz Could you check this, please?

@evrardjp evrardjp mentioned this pull request Nov 5, 2024
pkg/reboot/command.go Outdated Show resolved Hide resolved
Without this, we are loosing features based on previous logrus
implementation. Now, we will log the stdout and stderr for
each call.

Next to this, we ensure the call of the log. methods will be
ready for the switch to get rid of logrus in the future.

Signed-off-by: Jean-Philippe Evrard <[email protected]>
@evrardjp
Copy link
Collaborator Author

evrardjp commented Nov 6, 2024

@jonaz can you have a second look please?

@evrardjp
Copy link
Collaborator Author

evrardjp commented Nov 6, 2024

I tested commit 1 on a new env. It has good results.

@jonaz
Copy link

jonaz commented Nov 6, 2024

@evrardjp LGTM 👍

@evrardjp evrardjp merged commit 659e9fd into kubereboot:main Nov 6, 2024
18 checks passed
@evrardjp evrardjp deleted the fix_goroutine_leak branch November 6, 2024 17:54
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.

Leaking goroutines Constantly increasing memory usage since upgrade to 1.16.1
3 participants