Skip to content

perf: replace /dev/urandom | tr with openssl rand to fix CPU spike in gen_random_string#3887

Open
Kookiejarz wants to merge 3 commits intoMHSanaei:mainfrom
Kookiejarz:main
Open

perf: replace /dev/urandom | tr with openssl rand to fix CPU spike in gen_random_string#3887
Kookiejarz wants to merge 3 commits intoMHSanaei:mainfrom
Kookiejarz:main

Conversation

@Kookiejarz
Copy link

closes #3886

Replace /dev/urandom | tr pipeline with openssl rand -base64 to reduce
tr's byte rejection rate from ~75% to ~2%, fixing CPU spikes on low-spec VPS.

See issue #3886 for detailed analysis.

…mness in install.sh

The previous implementation using cat /dev/urandom | tr caused tr to hang and consume 100% CPU on certain environments (e.g., GCP, specific kernels) due to delayed SIGPIPE handling. Using openssl provides a finite, cryptographically secure string that eliminates this CPU spike and is noticeably faster."
Copilot AI review requested due to automatic review settings March 5, 2026 03:26
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b01a71f32d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This comment was marked as outdated.

@cherts
Copy link
Contributor

cherts commented Mar 5, 2026

Maybe it's worth using a simpler and lighter program - pwgen ?

@Kookiejarz
Copy link
Author

Maybe it's worth using a simpler and lighter program - pwgen ?

Thanks for the suggestion! pwgen is indeed a great and lightweight tool specifically designed for this purpose. :D

However, for a self-contained installation script, introducing pwgen would mean adding a highly specific, single-purpose dependency. While the PR does add openssl to the package manager lists, openssl is a ubiquitous core utility that is almost universally available across all distributions (including minimal ISOs and Alpine) - and also an implicit dependency via curl, which is required for the one-click installation.

Using openssl rand -base64 also provides cryptographically secure pseudo-randomness (CSPRNG) without adding additional single-use tools to the system, keeping it lightweight.

@MHSanaei
Copy link
Owner

MHSanaei commented Mar 8, 2026

Thanks for your PR
we have two more gen_random_string on x-ui.sh and update.sh

@Kookiejarz
Copy link
Author

Thanks for your PR we have two more gen_random_string on x-ui.sh and update.sh

Got it, already modified and commited. :)

@MHSanaei MHSanaei force-pushed the main branch 2 times, most recently from 0dc4df2 to f0f98c7 Compare March 17, 2026 22:01
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.

perf: gen_random_string causes high CPU usage due to 75% byte rejection in tr

4 participants