diff --git a/app/http.php b/app/http.php index aa9e5e0..9c54cee 100644 --- a/app/http.php +++ b/app/http.php @@ -1023,8 +1023,14 @@ function (string $runtimeId, ?string $payload, string $path, string $method, arr break; } + // Unknown protocol error code, but also means parsing issue + // As patch, we consider this too big entry for headers (logs&errors) + if ($executionResponse['errNo'] === 7102) { + throw new Exception('Invalid response. This usually means too large logs or errors. Please avoid logging files or lengthy strings.', 500); + } + if ($executionResponse['errNo'] !== 111) { // Connection Refused - see https://openswoole.com/docs/swoole-error-code - throw new Exception('An internal curl error has occurred within the executor! Error Msg: ' . $executionResponse['error'], 500); + throw new Exception('An internal curl error has occurred within the executor! Error Number: ' . $executionResponse['errNo'] . '. Error Msg: ' . $executionResponse['error'], 500); } if ($i === 9) { diff --git a/tests/ExecutorTest.php b/tests/ExecutorTest.php index db20ff1..7d32e82 100644 --- a/tests/ExecutorTest.php +++ b/tests/ExecutorTest.php @@ -300,6 +300,18 @@ public function provideScenarios(): array $this->assertEmpty($response['body']['logs']); } ], + [ + 'image' => 'openruntimes/node:v3-18.0', + 'entrypoint' => 'index.js', + 'folder' => 'node-large-logs', + 'version' => 'v3', + 'startCommand' => 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh "pm2 start src/server.js --no-daemon"', + 'buildCommand' => 'tar -zxf /tmp/code.tar.gz -C /mnt/code && helpers/build.sh "npm i"', + 'assertions' => function ($response) { + $this->assertEquals(500, $response['headers']['status-code']); + $this->assertStringContainsString('Invalid response. This usually means too large logs or errors', $response['body']['message']); + } + ], ]; } diff --git a/tests/resources/functions/node-large-logs/index.js b/tests/resources/functions/node-large-logs/index.js new file mode 100644 index 0000000..71e07f7 --- /dev/null +++ b/tests/resources/functions/node-large-logs/index.js @@ -0,0 +1,14 @@ +module.exports = async (context) => { + let log1kb = ''; + + for(let i = 0; i < 1024; i++) { + log1kb += "A"; + } + + // 1MB log + for(let i = 0; i < 1024; i++) { + context.log(log1kb); + } + + return context.res.send('OK'); +} \ No newline at end of file diff --git a/tests/resources/functions/node-large-logs/package.json b/tests/resources/functions/node-large-logs/package.json new file mode 100644 index 0000000..82b08e6 --- /dev/null +++ b/tests/resources/functions/node-large-logs/package.json @@ -0,0 +1,12 @@ +{ + "name": "large-logs", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +}