Skip to content

Commit

Permalink
Attempt to handle startup that didn't crash but still timed out
Browse files Browse the repository at this point in the history
  • Loading branch information
trappar committed Feb 15, 2024
1 parent bf20646 commit adeb47e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
11 changes: 6 additions & 5 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2820,11 +2820,7 @@ const readLog = async (name) => {
return '';
}
};
;// CONCATENATED MODULE: ./src/post.js




;// CONCATENATED MODULE: ./src/pidIsRunning.js
function pidIsRunning(pid) {
try {
process.kill(pid, 0);
Expand All @@ -2833,6 +2829,11 @@ function pidIsRunning(pid) {
return false;
}
}
;// CONCATENATED MODULE: ./src/post.js





async function post() {
const pid = parseInt((0,core.getState)('pid'));
Expand Down
18 changes: 16 additions & 2 deletions dist/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6098,6 +6098,15 @@ const readLog = async (name) => {
return '';
}
};
;// CONCATENATED MODULE: ./src/pidIsRunning.js
function pidIsRunning(pid) {
try {
process.kill(pid, 0);
return true;
} catch (e) {
return false;
}
}
;// CONCATENATED MODULE: ./src/start.js


Expand All @@ -6109,6 +6118,7 @@ const readLog = async (name) => {




const start_dirname = (0,external_node_path_namespaceObject.dirname)((0,external_url_namespaceObject.fileURLToPath)(import.meta.url));

async function getPort() {
Expand Down Expand Up @@ -6151,7 +6161,7 @@ async function main() {

try {
(0,core.debug)(`Waiting for port ${port} to be used...`);
await (0,tcp_port_used/* waitUntilUsedOnHost */.S7)(port, host, 250, 5000);
await (0,tcp_port_used/* waitUntilUsedOnHost */.S7)(port, host, 250, 10000);
(0,core.info)('Spawned Turbo Cache Server:');
(0,core.info)(` PID: ${pid}`);
(0,core.info)(` Listening on port: ${port}`);
Expand All @@ -6164,9 +6174,13 @@ async function main() {

process.exit(0);
} catch (e) {
if (pidIsRunning(pid)) {
(0,core.debug)(`Timed out while waiting for Turbo Cache Server, yet process is running. Stopping PID: ${pid}...`);
process.kill(pid);
}
const errors = await readLog('err');
const errorMessage = errors ? `\nServer error log:\n${indentMultiline(errors)}` : '';
throw new Error(`Turbo server failed to start on port: ${port}${errorMessage}`);
throw new Error(`Turbo Cache Server failed to start on port: ${port}${errorMessage}`);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/pidIsRunning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function pidIsRunning(pid) {
try {
process.kill(pid, 0);
return true;
} catch (e) {
return false;
}
}
10 changes: 1 addition & 9 deletions src/post.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { debug, getState, info, setFailed } from '@actions/core';
import { indentMultiline } from './indentMultiline.js';
import { readLog } from './logs.js';

function pidIsRunning(pid) {
try {
process.kill(pid, 0);
return true;
} catch (e) {
return false;
}
}
import { pidIsRunning } from './pidIsRunning.js';

async function post() {
const pid = parseInt(getState('pid'));
Expand Down
9 changes: 7 additions & 2 deletions src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { fileURLToPath } from 'url';
import { indentMultiline } from './indentMultiline.js';
import { host, port, storagePath, storageProvider, teamId, token } from './inputs.js';
import { readLog } from './logs.js';
import { pidIsRunning } from './pidIsRunning.js';

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -56,7 +57,7 @@ async function main() {

try {
debug(`Waiting for port ${port} to be used...`);
await waitUntilUsedOnHost(port, host, 250, 5000);
await waitUntilUsedOnHost(port, host, 250, 10000);
info('Spawned Turbo Cache Server:');
info(` PID: ${pid}`);
info(` Listening on port: ${port}`);
Expand All @@ -69,9 +70,13 @@ async function main() {

process.exit(0);
} catch (e) {
if (pidIsRunning(pid)) {
debug(`Timed out while waiting for Turbo Cache Server, yet process is running. Stopping PID: ${pid}...`);
process.kill(pid);
}
const errors = await readLog('err');
const errorMessage = errors ? `\nServer error log:\n${indentMultiline(errors)}` : '';
throw new Error(`Turbo server failed to start on port: ${port}${errorMessage}`);
throw new Error(`Turbo Cache Server failed to start on port: ${port}${errorMessage}`);
}
}

Expand Down

0 comments on commit adeb47e

Please sign in to comment.