Skip to content

Commit a9597b2

Browse files
Anubhav SinghAnubhav Singh
authored andcommitted
Check glibc version at startup and abort if below 2.28
Fixes #9551 Signed-off-by: Anubhav Singh <anubhavsingh@Anubhavs-MacBook-Air.local>
1 parent 05b6c1a commit a9597b2

File tree

1 file changed

+69
-7
lines changed

1 file changed

+69
-7
lines changed

app/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,18 @@ public String build() {
507507
lines.add("Maximum heap size: " + normalizeSize(Runtime.getRuntime().maxMemory()));
508508
lines.add("OS: " + PlatformDetector.getOS());
509509

510-
if (SystemInfo.getCurrentPlatform() == PlatformEnum.LINUX) {
511-
final String glibcVersion = PlatformDetector.getGlibc();
512-
if (glibcVersion != null) {
513-
lines.add("glibc: " + glibcVersion);
514-
}
510+
if (SystemInfo.getCurrentPlatform() == PlatformEnum.LINUX) {
511+
final String glibcVersion = PlatformDetector.getGlibc();
512+
513+
514+
checkGlibcVersion(glibcVersion);
515+
516+
if (glibcVersion != null) {
517+
lines.add("glibc: " + glibcVersion);
518+
}
515519

516-
detectJemalloc(lines);
517-
}
520+
detectJemalloc(lines);
521+
}
518522

519523
final HardwareAbstractionLayer hardwareInfo = new SystemInfo().getHardware();
520524

@@ -565,6 +569,64 @@ private void detectJemalloc(final List<String> lines) {
565569
});
566570
}
567571

572+
573+
/**
574+
* Checks if the glibc version meets the minimum required version.
575+
*
576+
* @param glibcVersion the detected glibc version
577+
*/
578+
private void checkGlibcVersion(final String glibcVersion) {
579+
if (glibcVersion == null) {
580+
// Cannot determine version, log warning but allow startup
581+
logger.warn("Unable to determine glibc version. Minimum required version is 2.28");
582+
return;
583+
}
584+
585+
final String minVersion = "2.28";
586+
if (!isGlibcVersionSufficient(glibcVersion, minVersion)) {
587+
logger.error("Insufficient glibc version detected.");
588+
logger.error("Required: {} or higher", minVersion);
589+
logger.error("Found: {}", glibcVersion);
590+
logger.error("Please upgrade your system's glibc to version {} or higher.", minVersion);
591+
throw new RuntimeException(
592+
"Besu requires glibc version " + minVersion + " or higher. Found: " + glibcVersion);
593+
}
594+
}
595+
596+
/**
597+
598+
* Compares glibc version strings.
599+
*
600+
* @param current the current glibc version
601+
* @param required the required minimum version
602+
* @return true if current version is sufficient, false otherwise
603+
*/
604+
605+
private boolean isGlibcVersionSufficient(final String current, final String required) {
606+
try {
607+
final String[] currentParts = current.split("\\.");
608+
final String[] requiredParts = required.split("\\.");
609+
610+
for (int i = 0; i < Math.min(currentParts.length, requiredParts.length); i++) {
611+
final int currentNum = Integer.parseInt(currentParts[i].trim());
612+
final int requiredNum = Integer.parseInt(requiredParts[i].trim());
613+
614+
if (currentNum > requiredNum) {
615+
return true;
616+
}
617+
if (currentNum < requiredNum) {
618+
return false;
619+
}
620+
}
621+
return true; // Versions are equal
622+
} catch (final NumberFormatException e) {
623+
logger.warn("Unable to parse glibc version: {}", current, e);
624+
return true; // Assume sufficient if unable to parse
625+
}
626+
}
627+
628+
629+
568630
/**
569631
* Normalize gas string.<br>
570632
* The implemented logic is<br>

0 commit comments

Comments
 (0)