Skip to content

Fix goroutine leak#1015

Merged
evrardjp merged 2 commits intokubereboot:mainfrom
evrardjp:fix_goroutine_leak
Nov 6, 2024
Merged

Fix goroutine leak#1015
evrardjp merged 2 commits intokubereboot:mainfrom
evrardjp:fix_goroutine_leak

Conversation

@evrardjp
Copy link
Copy Markdown
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 <open-source@a.spamming.party>
@evrardjp
Copy link
Copy Markdown
Collaborator Author

evrardjp commented Nov 5, 2024

@jonaz Could you check this, please?

@evrardjp evrardjp mentioned this pull request Nov 5, 2024
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 <open-source@a.spamming.party>
@evrardjp
Copy link
Copy Markdown
Collaborator Author

evrardjp commented Nov 6, 2024

@jonaz can you have a second look please?

@evrardjp
Copy link
Copy Markdown
Collaborator Author

evrardjp commented Nov 6, 2024

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

@jonaz
Copy link
Copy Markdown

jonaz commented Nov 6, 2024

@evrardjp LGTM 👍

@evrardjp evrardjp merged commit 659e9fd into kubereboot:main Nov 6, 2024
@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