Fix edgecase with socketpair() impacting shell and spawn (#15725)

This commit is contained in:
Jarred Sumner
2024-12-12 01:23:40 -08:00
committed by GitHub
parent fddc28d608
commit 2ccdf0122c
7 changed files with 233 additions and 78 deletions

View File

@@ -26,7 +26,7 @@ import {
getBuildUrl,
getEnv,
getFileUrl,
getLoggedInUserCount,
getLoggedInUserCountOrDetails,
getShell,
getWindowsExitReason,
isBuildkite,
@@ -1499,7 +1499,7 @@ export async function main() {
let waitForUser = false;
while (isCI) {
const userCount = getLoggedInUserCount();
const userCount = getLoggedInUserCountOrDetails();
if (!userCount) {
if (waitForUser) {
!isQuiet && console.log("No users logged in, exiting runner...");
@@ -1509,7 +1509,11 @@ export async function main() {
if (!waitForUser) {
startGroup("Summary");
console.warn(`Found ${userCount} users logged in, keeping the runner alive until logout...`);
if (typeof userCount === "number") {
console.warn(`Found ${userCount} users logged in, keeping the runner alive until logout...`);
} else {
console.warn(userCount);
}
waitForUser = true;
}

View File

@@ -2688,7 +2688,7 @@ export function printEnvironment() {
/**
* @returns {number | undefined}
*/
export function getLoggedInUserCount() {
export function getLoggedInUserCountOrDetails() {
if (isWindows) {
const pwsh = which(["pwsh", "powershell"]);
if (pwsh) {
@@ -2705,7 +2705,31 @@ export function getLoggedInUserCount() {
const { error, stdout } = spawnSync(["who"]);
if (!error) {
return stdout.split("\n").filter(line => /tty|pts/i.test(line)).length;
const users = stdout
.split("\n")
.filter(line => /tty|pts/i.test(line))
.map(line => {
// who output format: username terminal date/time (ip)
const [username, terminal, datetime, ip] = line.split(/\s+/);
return {
username,
terminal,
datetime,
ip: (ip || "").replace(/[()]/g, ""), // Remove parentheses from IP
};
});
if (users.length === 0) {
return 0;
}
let message = users.length + " currently logged in users:";
for (const user of users) {
message += `\n- ${user.username} on ${user.terminal} since ${user.datetime}${user.ip ? ` from ${user.ip}` : ""}`;
}
return message;
}
}