Skip to content

cli: correctly obtain GOMEMLIMIT env var value#101498

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:fix-gomemlimit
Apr 14, 2023
Merged

cli: correctly obtain GOMEMLIMIT env var value#101498
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:fix-gomemlimit

Conversation

@yuzefovich
Copy link
Copy Markdown
Member

@yuzefovich yuzefovich commented Apr 13, 2023

This commit fixes how the value of GOMEMLIMIT env var is obtained in case --max-go-memory is not specified. Previously, we were using envutil.Env* method which assumes that the env var is internal (i.e. has COCKROACH_ prefix), so it would result in a panic on startup. Now we properly obtain the value as for external env var.

Fixes: #https://github.com/cockroachlabs/support/issues/2228.

Epic: None

Release note (bug fix): CockroachDB 23.1.0 alpha and beta versions previously would panic on start command when GOMEMLIMIT env var was set and --max-go-memory flag wasn't specified, and this is now fixed.

@yuzefovich yuzefovich added backport-23.1.x PAST MAINTENANCE SUPPORT: 23.1 patch releases via ER request only backport-23.1.0 labels Apr 13, 2023
@yuzefovich yuzefovich requested a review from knz April 13, 2023 21:25
@yuzefovich yuzefovich requested review from a team as code owners April 13, 2023 21:25
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Apr 13, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

this seems like the easiest fix, so makes sense to go with it. but i also wonder if the GoMemLimit flag should be changed to use the EnvVar field:

diff --git a/pkg/cli/cliflags/flags.go b/pkg/cli/cliflags/flags.go
index 0c06a8bfb85..571b16939ba 100644
--- a/pkg/cli/cliflags/flags.go
+++ b/pkg/cli/cliflags/flags.go
@@ -171,6 +171,7 @@ and 1GiB) or a percentage of physical memory (e.g. .25). If left unspecified,
 defaults to 2.25x of --max-sql-memory (subject to max-go-memory + 1.15x --cache
 not exceeding 90% of available RAM). Set to 0 to disable the soft memory limit
 (not recommended).`,
+        EnvVar: "GOMEMLIMIT",
     }

     TSDBMem = FlagInfo{

also, i think there could be a test for this in cli/interactive_tests

@yuzefovich
Copy link
Copy Markdown
Member Author

but i also wonder if the GoMemLimit flag should be changed to use the EnvVar field:

On a quick glance, that EnvVar flag assumes that it's for "internal" vars, with COCKROACH_ prefix (see FlagInfo.Usage).

also, i think there could be a test for this in cli/interactive_tests

I made an attempt to add the corresponding test, but I don't think I did it right (the test times out for me locally before and after the fix with expect -d -f pkg/cli/interactive_tests/test_flags.tcl ./cockroach). Could you provide some more guidance or some hints to what I'm doing wrong?

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Oh oops 🤦‍♂️

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

What you did wrong in your test is not using the start_server command like in other tests.

This commit fixes how the value of GOMEMLIMIT env var is obtained in
case `--max-go-memory` is not specified. Previously, we were using
`envutil.Env*` method which assumes that the env var is internal (i.e.
has `COCKROACH_` prefix), so it would result in a panic on start up. Now
we properly obtain the value as for external env var.

Release note (bug fix): CockroachDB 23.1.0 alpha and beta versions
previously would panic on `start` command when `GOMEMLIMIT` env var was
set and `--max-go-memory` flag wasn't specified, and this is now fixed.
@yuzefovich
Copy link
Copy Markdown
Member Author

I was actually missing stop_server before my new subtest. I also tried using start_server instead of explicit send ... start-single-node, but that didn't reproduce the problem - my guess is that env var isn't propagated into start_server command.

@yuzefovich
Copy link
Copy Markdown
Member Author

TFTRs!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 14, 2023

Build succeeded:

@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Apr 14, 2023

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error setting assignees, but backport branch blathers/backport-release-23.1-101498 is ready: Post "https://api.github.com/repos/cockroachdb/cockroach/issues/101564/assignees": read tcp 169.254.8.1:56047->140.82.114.5:443: read: connection reset by peer

Backport to branch 23.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-23.1.x PAST MAINTENANCE SUPPORT: 23.1 patch releases via ER request only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants