Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add exception for large logs #49

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions tests/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
],
];
}

Expand Down
14 changes: 14 additions & 0 deletions tests/resources/functions/node-large-logs/index.js
Original file line number Diff line number Diff line change
@@ -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');
}
12 changes: 12 additions & 0 deletions tests/resources/functions/node-large-logs/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
Loading