forked from extern/bruno
Count the number of jumps to break out of infinite loops.
This is especially useful for the bru cli, to make sure that test-runners that are accidentally stuck in an infinite loop still terminate in a reasonable amount of time and don't hog up resources.
This commit is contained in:
parent
db0de68987
commit
129d659628
@ -356,6 +356,7 @@ const handler = async function (argv) {
|
||||
}
|
||||
|
||||
let currentRequestIndex = 0;
|
||||
let nJumps = 0; // count the number of jumps to avoid infinite loops
|
||||
while (currentRequestIndex < bruJsons.length) {
|
||||
const iter = bruJsons[currentRequestIndex];
|
||||
const { bruFilepath, bruJson } = iter;
|
||||
@ -372,6 +373,11 @@ const handler = async function (argv) {
|
||||
|
||||
const nextRequestName = result?.nextRequestName;
|
||||
if (nextRequestName) {
|
||||
nJumps++;
|
||||
if (nJumps > 10000) {
|
||||
console.error(chalk.red(`Too many jumps, possible infinite loop`));
|
||||
process.exit(1);
|
||||
}
|
||||
const nextRequestIdx = bruJsons.findIndex((iter) => iter.bruJson.name === nextRequestName);
|
||||
if (nextRequestIdx >= 0) {
|
||||
currentRequestIndex = nextRequestIdx;
|
||||
|
@ -673,9 +673,10 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
}
|
||||
|
||||
let currentRequestIndex = 0;
|
||||
let nJumps = 0; // count the number of jumps to avoid infinite loops
|
||||
while (currentRequestIndex < folderRequests.length) {
|
||||
item = folderRequests[currentRequestIndex];
|
||||
let nextRequestName = undefined;
|
||||
const item = folderRequests[currentRequestIndex];
|
||||
let nextRequestName;
|
||||
const itemUid = item.uid;
|
||||
const eventData = {
|
||||
collectionUid,
|
||||
@ -866,6 +867,10 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
});
|
||||
}
|
||||
if (nextRequestName) {
|
||||
nJumps++;
|
||||
if (nJumps > 10000) {
|
||||
throw new Error('Too many jumps, possible infinite loop');
|
||||
}
|
||||
const nextRequestIdx = folderRequests.findIndex((request) => request.name === nextRequestName);
|
||||
if (nextRequestIdx >= 0) {
|
||||
currentRequestIndex = nextRequestIdx;
|
||||
|
Loading…
Reference in New Issue
Block a user