From 7fac836cdcc66fcfc5b08316e2207a6bd1e08623 Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Mon, 16 Jun 2025 09:56:15 +0530 Subject: [PATCH 01/11] feat: update test cases with improved script formatting and memory usage estimates --- tests/data/testJson.js | 255 ++++++++++++++++++++++++++--------------- 1 file changed, 164 insertions(+), 91 deletions(-) diff --git a/tests/data/testJson.js b/tests/data/testJson.js index 823b5b35..5a71dd0f 100644 --- a/tests/data/testJson.js +++ b/tests/data/testJson.js @@ -1,18 +1,20 @@ + const testCases = [ { name: 'cpp : hello world', reqObject: { language: 'cpp', - script: - '#include\n' + - 'using namespace std;\n' + - 'int main(){\n' + - ' cout << "hello world";\n' + - 'return 0;\n' + - '}\n', + script: ` +#include +using namespace std; +int main(){ + cout << "hello world"; + return 0; +}`, }, expectedResponse: { val: 'hello world', + approxMemoryUses: 2744, status: 200, error: 0, }, @@ -21,20 +23,21 @@ const testCases = [ name: 'cpp : print stdin', reqObject: { language: 'cpp', - script: - '#include\n\n' + - 'using namespace std;\n' + - 'int main(){\n\n' + - ' int a;\n' + - ' while(cin >> a){\n' + - ' cout << a << endl;\n' + - ' }\n' + - ' return 0;\n\n' + - '}\n', + script: ` +#include +using namespace std; +int main(){ + int a; + while(cin >> a){ + cout << a << endl; + } + return 0; +}`, stdin: '1 2 3', }, expectedResponse: { val: '1\n2\n3\n', + approxMemoryUses: 2680, status: 200, error: 0, }, @@ -44,10 +47,11 @@ const testCases = [ name: 'nodejs : hello world', reqObject: { language: 'nodejs', - script: 'console.log(\'hello world\')', + script: `console.log('hello world')`, }, expectedResponse: { val: 'hello world\n', + approxMemoryUses: 44540, status: 200, error: 0, }, @@ -56,16 +60,16 @@ const testCases = [ name: 'nodejs : print stdin', reqObject: { language: 'nodejs', - script: - 'process.stdin.setEncoding(\'utf8\'); \n ' + - 'process.stdin.on(\'data\', (input) => { \n ' + - ' console.log(input); \n ' + - ' \n ' + - '}); \n ', + script: ` +process.stdin.setEncoding('utf8'); +process.stdin.on('data', (input) => { +console.log(input.trim()); +});`, stdin: '1 2 3', }, expectedResponse: { val: '1 2 3\n', + approxMemoryUses: 44888, status: 200, error: 0, }, @@ -74,10 +78,12 @@ const testCases = [ name: 'python : hello world', reqObject: { language: 'python', - script: 'print(\'hello world\')', + script: + `print('hello world')`, }, expectedResponse: { val: 'hello world\n', + approxMemoryUses: 5544, status: 200, error: 0, }, @@ -86,19 +92,15 @@ const testCases = [ name: 'python : print stdin', reqObject: { language: 'python', - script: - 'try:\n' + - ' while(True):\n' + - ' line = input()\n' + - ' if not line:\n' + - ' break\n' + - ' print(line)\n' + - 'except EOFError:\n' + - ' pass', + script: ` +import sys +for line in sys.stdin: + print(line.strip())`, stdin: '1 2 3', }, expectedResponse: { val: '1 2 3\n', + approxMemoryUses: 5800, status: 200, error: 0, }, @@ -108,14 +110,15 @@ const testCases = [ reqObject: { language: 'c', script: - '#include\n\n' + - 'int main(){\n\n' + - ' printf("hello world");\n' + - ' return 0;\n' + - '}\n', + `#include +int main(){ +printf("hello world"); +return 0; +} `, }, expectedResponse: { val: 'hello world', + approxMemoryUses: 900, status: 200, error: 0, }, @@ -124,37 +127,40 @@ const testCases = [ name: 'c : print stdin', reqObject: { language: 'c', - script: - '#include \n' + - 'int main() {\n' + - ' int number;\n' + - ' while (scanf("%d", &number) == 1) {\n' + - ' printf("%d\\n", number);\n' + - ' } \n' + - ' return 0;\n' + - '}', + script:` +#include +int main() { + int number; + while (scanf("%d", &number) == 1) { + printf("%d\\n", number); +} + return 0; +} `, stdin: '1 2 3', }, expectedResponse: { val: '1\n2\n3\n', + approxMemoryUses: 924, status: 200, error: 0, }, }, { - name: 'java : print stdin', + name: 'java : hello world', reqObject: { language: 'java', script: - 'import java.util.Scanner;\n' + - 'public class Solution {\n' + - ' public static void main(String[] args) {\n' + - ' System.out.println("hello world");\n' + - ' }\n' + - '}\n', + ` +import java.util.Scanner; +public class Solution { + public static void main(String[] args) { + System.out.println("hello world"); + } +}`, }, expectedResponse: { val: 'hello world\n', + approxMemoryUses: 33000, status: 200, error: 0, }, @@ -163,22 +169,23 @@ const testCases = [ name: 'java : print stdin', reqObject: { language: 'java', - script: - 'import java.util.Scanner;\n' + - 'public class Solution {\n' + - ' public static void main(String[] args) {\n' + - ' Scanner scanner = new Scanner(System.in);\n' + - ' while (scanner.hasNextInt()) {\n' + - ' int number = scanner.nextInt();\n' + - ' System.out.println(number);\n' + - ' } \n' + - ' scanner.close();\n' + - ' }\n' + - '}\n', + script: ` +import java.util.Scanner; +public class Solution { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + while (scanner.hasNextInt()) { + int number = scanner.nextInt(); + System.out.println(number); + } + scanner.close(); + } +} `, stdin: '1 2 3', }, expectedResponse: { val: '1\n2\n3\n', + approxMemoryUses: 35900, status: 200, error: 0, }, @@ -188,10 +195,11 @@ const testCases = [ reqObject: { language: 'ruby', script: - 'print "hello world"' + `print "hello world"`, }, expectedResponse: { val: 'hello world', + approxMemoryUses: 22800, status: 200, error: 0, }, @@ -200,13 +208,14 @@ const testCases = [ name: 'ruby : print stdin', reqObject: { language: 'ruby', - script: - 'user_input = gets.chomp\n' + - 'puts user_input', - stdin: '10\n' + script: ` +user_input = gets.chomp +puts user_input`, + stdin: '10', }, expectedResponse: { val: '10\n', + approxMemoryUses: 22800, status: 200, error: 0, }, @@ -215,7 +224,8 @@ const testCases = [ name: 'TLE test', reqObject: { language: 'nodejs', - script: 'for(let i=0 ; ; ){i++}', + script: + `for(let i = 0 ;; ) { i++ } `, }, expectedResponse: { val: 'Time limit exceeded', @@ -227,7 +237,8 @@ const testCases = [ name: 'MLE test', reqObject: { language: 'python', - script: 'one_gb_data = bytearray(1000 * 1024 * 1024)', + script: + `one_gb_data = bytearray(1000 * 1024 * 1024)`, }, expectedResponse: { val: 'Memory limit exceeded', @@ -239,19 +250,19 @@ const testCases = [ name: 'MLE test 2', reqObject: { language: 'python', - script: - 'import time\n' + - 'def consume_memory(target_mb, duration_sec):\n' + - ' float_size = 8\n' + - ' floats_per_mb = (1024 * 1024) // float_size\n' + - ' total_floats = target_mb * floats_per_mb\n' + - ' iterations = int(duration_sec / 0.1)\n' + - ' floats_per_iteration = total_floats // iterations\n' + - ' memory_hog = []\n' + - ' for _ in range(iterations):\n' + - ' memory_hog.extend([0.0] * floats_per_iteration)\n' + - ' time.sleep(0.1)\n' + - 'consume_memory(1000, 1)\n', + script: ` +import time +def consume_memory(target_mb, duration_sec): + float_size = 8 + floats_per_mb = (1024 * 1024) // float_size + total_floats = target_mb * floats_per_mb + iterations = int(duration_sec / 0.1) + floats_per_iteration = total_floats // iterations + memory_hog = [] + for _ in range(iterations): + memory_hog.extend([0.0] * floats_per_iteration) + time.sleep(0.1) +consume_memory(1000, 1)`, }, expectedResponse: { val: 'Memory limit exceeded', @@ -263,10 +274,11 @@ const testCases = [ name: 'MLE test 3', reqObject: { language: 'python', - script: - 'a = [100]\n' + - 'for i in a:\n' + - ' a.append(i)\n', + script: ` +a = [100] +for i in a: + a.append(i) + `, }, expectedResponse: { val: 'Memory limit exceeded', @@ -298,6 +310,67 @@ const testCases = [ error: 0, }, }, + { + name: 'c :Heap memory allocation', + reqObject: { + language: 'c', + script: ` +#include +#include +int main() { + size_t memory_size = 50 * 1024 * 1024; + char *memory_block = malloc(memory_size); + if (memory_block == NULL) { + printf("Failed to allocate memory\\n"); + return 1; + } + printf("Memory allocation done\\n"); + for (size_t i = 0; i < memory_size; i += 4096) { + memory_block[i] = (char)(i % 256); + } + printf("Memory touched and initialized\\n"); + free(memory_block); + printf("Memory freed\\n"); + return 0; +} `, + }, + expectedResponse: { + val: 'Memory allocation done\nMemory touched and initialized\nMemory freed\n', + status: 200, + error: 0, + approxMemoryUses: 51000, + }, + }, + { + name: 'c :Stack memory allocation', + reqObject: { + language: 'c', + script: ` +#include +#include +#define ONE_MB (1024 * 1024) +void stack_allocate(int remaining_bytes, int depth) { + if (remaining_bytes <= 0) { + printf("Memory allocated on stack\\n"); + return; + } + char buffer[ONE_MB]; + memset(buffer, 0, ONE_MB); // Touch the memory + stack_allocate(remaining_bytes - ONE_MB, depth + 1); +} +int main() { + stack_allocate(6 * ONE_MB, 0); + return 0; +} `, + }, + expectedResponse: { + val: 'Memory allocated on stack\n', + status: 200, + error: 0, + approxMemoryUses: 6500, // Max stack uses limit is ~10 MB + }, + }, + ] module.exports = { testCases } From 531fc0b12da5ae722c97e7de48d965f3a223b839 Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Mon, 16 Jun 2025 09:56:25 +0530 Subject: [PATCH 02/11] feat: add memory usage validation to test cases with tolerance checks --- tests/test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test.js b/tests/test.js index 7cd19621..78027b23 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,9 +1,13 @@ + const axios = require('axios') const { testCases } = require('./data/testJson') const { describe, expect, it } = require('@jest/globals') const ENDPOINT = process.env.ENDPOINT || 'http://localhost:3000/api/execute/' +// Memory comparison tolerance in percent (e.g., 20 means ±20%) +const MEMORY_TOLERANCE_PERCENT = 20 + describe('Tests', () => { for (const testCase of testCases) { it(testCase.name, async () => { @@ -15,6 +19,13 @@ describe('Tests', () => { expect(response.data.output.points).toBeDefined() } else { expect(response).toHaveProperty('data.output', testCase.expectedResponse.val) + if (testCase.expectedResponse.approxMemoryUses) { + const actual = response.data.memory + const expected = testCase.expectedResponse.approxMemoryUses + const tolerance = (MEMORY_TOLERANCE_PERCENT / 100) * expected + expect(actual).toBeGreaterThanOrEqual(expected - tolerance) + expect(actual).toBeLessThanOrEqual(expected + tolerance) + } } expect(response).toHaveProperty('status', testCase.expectedResponse.status) expect(response).toHaveProperty('data.error', testCase.expectedResponse.error) From 90f3f175d19ff6e3076a76247c29ded04991c59a Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Mon, 16 Jun 2025 09:57:03 +0530 Subject: [PATCH 03/11] feat: add memory monitoring during code execution --- services/code.service.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/services/code.service.js b/services/code.service.js index cf93b08d..a0e247ff 100644 --- a/services/code.service.js +++ b/services/code.service.js @@ -1,3 +1,4 @@ + /* globals gc */ const util = require('util') const exec = util.promisify(require('child_process').exec) @@ -230,9 +231,10 @@ const _executeCode = async (req, res, response) => { let command if (language === 'java') { // Remove ulimit as a temp fix - command = `cd /tmp/ && timeout ${langConfig.timeout}s ${langConfig.run}` + command = `cd /tmp/ && /usr/bin/time -f "%M" -o /tmp/memory_report.txt timeout ${langConfig.timeout}s ${langConfig.run}` } else { - command = `cd /tmp/ && ulimit -v ${langConfig.memory} && ulimit -m ${langConfig.memory} && timeout ${langConfig.timeout}s ${langConfig.run}` + // Execute command with memory limits and resource monitoring for non-Java languages + command = `cd /tmp/ && ulimit -v ${langConfig.memory} && ulimit -m ${langConfig.memory} && /usr/bin/time -f "%M" -o /tmp/memory_report.txt timeout ${langConfig.timeout}s ${langConfig.run}` } // Check if there is any input that is to be provided to code execution @@ -244,14 +246,31 @@ const _executeCode = async (req, res, response) => { } const outputLog = await _runScript(command, res, true) + + let memoryKB = null + try { + const path = '/tmp/memory_report.txt' + await fs.promises.access(path, fs.constants.F_OK) + const memoryReport = await fs.promises.readFile(path, 'utf8') + memoryKB = parseInt(memoryReport.trim(), 10) + } catch (err) { + console.warn(`Memory report not found or failed to read: ${err.message}`) + } + + // Adjust if you're on Alpine to divide by 4 + response.memory = memoryKB ? memoryKB / 4 : null + console.log('memory used', response.memory) + response.output = outputLog.error !== undefined ? _prepareErrorMessage(outputLog, language, command) : outputLog.result.stdout + if (outputLog.error) { response.error = 1 } - } else { + } + else { response.error = 1 } } catch (e) { @@ -399,7 +418,7 @@ const _getAiScore = async (langConfig, question, response, points, userAnswer, r const _executeStatement = (db, sql) => { return new Promise((resolve, reject) => { - db.all(sql, function(err, rows) { + db.all(sql, function (err, rows) { if (err) { reject(err); } else { @@ -887,14 +906,14 @@ const _postCleanUp = async (type, staticServerInstance = undefined, jasmineServe await _cleanUpDir(appConfig.multifile.workingDir, appConfig.multifile.submissionFileDownloadPath) switch (type) { case FRONTEND_STATIC_JASMINE: - if(staticServerInstance) { + if (staticServerInstance) { staticServerInstance.close(() => { logger.info('Exiting static server in post cleanup') }) } break case FRONTEND_REACT_JASMINE: - if(jasmineServer) { + if (jasmineServer) { logger.info('Exiting react setup server in post cleanup') process.kill(-jasmineServer.pid) } @@ -917,7 +936,7 @@ const _executeMultiFile = async (req, res, response) => { let result if (req?.non_editable_files) { const isValidSubmission = await _checkIntegrity(req.non_editable_files) - if(!isValidSubmission) throw new Error(`A non editable file has been modified, exiting...`) + if (!isValidSubmission) throw new Error(`A non editable file has been modified, exiting...`) } switch (req.type) { case FRONTEND_STATIC_JASMINE: From 7e4c212f27045334c4fceb8101c792172312f619 Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Mon, 16 Jun 2025 10:15:19 +0530 Subject: [PATCH 04/11] feat: enhance memory reporting for Alpine Linux environments --- services/code.service.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/code.service.js b/services/code.service.js index a0e247ff..0c5d82d9 100644 --- a/services/code.service.js +++ b/services/code.service.js @@ -257,9 +257,15 @@ const _executeCode = async (req, res, response) => { console.warn(`Memory report not found or failed to read: ${err.message}`) } - // Adjust if you're on Alpine to divide by 4 - response.memory = memoryKB ? memoryKB / 4 : null - console.log('memory used', response.memory) + const isAlpine = fs.existsSync('/etc/alpine-release'); + + if (memoryKB) { + response.memory = isAlpine ? memoryKB / 4 : memoryKB; + } else { + response.memory = null; + } + + console.log('Memory used:', response.memory); response.output = outputLog.error !== undefined From 253d7969ed9783ed807a148615a6e6fcb03fcd5e Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Mon, 16 Jun 2025 10:17:09 +0530 Subject: [PATCH 05/11] feat: enhance memory usage validation messages in test cases --- tests/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test.js b/tests/test.js index 78027b23..5321549f 100644 --- a/tests/test.js +++ b/tests/test.js @@ -23,8 +23,8 @@ describe('Tests', () => { const actual = response.data.memory const expected = testCase.expectedResponse.approxMemoryUses const tolerance = (MEMORY_TOLERANCE_PERCENT / 100) * expected - expect(actual).toBeGreaterThanOrEqual(expected - tolerance) - expect(actual).toBeLessThanOrEqual(expected + tolerance) + expect(actual).toBeGreaterThanOrEqual(expected - tolerance, `Memory usage should be within tolerance (min: ${expected - tolerance})`) + expect(actual).toBeLessThanOrEqual(expected + tolerance, `Memory usage should be within tolerance (max: ${expected + tolerance})`) } } expect(response).toHaveProperty('status', testCase.expectedResponse.status) From 28ea058cd0cb7302c7e30741c4802a334cccaf2e Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Mon, 16 Jun 2025 10:18:50 +0530 Subject: [PATCH 06/11] fix: change warning to error for memory report read failure --- services/code.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/code.service.js b/services/code.service.js index 0c5d82d9..dfe8cdce 100644 --- a/services/code.service.js +++ b/services/code.service.js @@ -254,7 +254,7 @@ const _executeCode = async (req, res, response) => { const memoryReport = await fs.promises.readFile(path, 'utf8') memoryKB = parseInt(memoryReport.trim(), 10) } catch (err) { - console.warn(`Memory report not found or failed to read: ${err.message}`) + console.error(`Memory report not found or failed to read: ${err.message}`) } const isAlpine = fs.existsSync('/etc/alpine-release'); From 048ddc3900fab5b0f31f94e5519a13f48fc62bd5 Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Tue, 17 Jun 2025 12:43:36 +0530 Subject: [PATCH 07/11] feat: update memory reporting path for code execution to use process ID and timestamp --- services/code.service.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/services/code.service.js b/services/code.service.js index dfe8cdce..cbda9f2b 100644 --- a/services/code.service.js +++ b/services/code.service.js @@ -228,13 +228,15 @@ const _executeCode = async (req, res, response) => { // Check if there is no compilation error if (response.compileMessage === '') { - let command + const memoryReportPath = `/tmp/memory_report_${process.pid}_${Date.now()}.txt`; + + let command; if (language === 'java') { // Remove ulimit as a temp fix - command = `cd /tmp/ && /usr/bin/time -f "%M" -o /tmp/memory_report.txt timeout ${langConfig.timeout}s ${langConfig.run}` + command = `cd /tmp/ && /usr/bin/time -f "%M" -o ${memoryReportPath} timeout ${langConfig.timeout}s ${langConfig.run}`; } else { // Execute command with memory limits and resource monitoring for non-Java languages - command = `cd /tmp/ && ulimit -v ${langConfig.memory} && ulimit -m ${langConfig.memory} && /usr/bin/time -f "%M" -o /tmp/memory_report.txt timeout ${langConfig.timeout}s ${langConfig.run}` + command = `cd /tmp/ && ulimit -v ${langConfig.memory} && ulimit -m ${langConfig.memory} && /usr/bin/time -f "%M" -o ${memoryReportPath} timeout ${langConfig.timeout}s ${langConfig.run}`; } // Check if there is any input that is to be provided to code execution @@ -249,9 +251,8 @@ const _executeCode = async (req, res, response) => { let memoryKB = null try { - const path = '/tmp/memory_report.txt' - await fs.promises.access(path, fs.constants.F_OK) - const memoryReport = await fs.promises.readFile(path, 'utf8') + await fs.promises.access(memoryReportPath, fs.constants.F_OK) + const memoryReport = await fs.promises.readFile(memoryReportPath, 'utf8') memoryKB = parseInt(memoryReport.trim(), 10) } catch (err) { console.error(`Memory report not found or failed to read: ${err.message}`) From cefcb7f2c7eb2841432d3a9060523156a6859fb7 Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Tue, 17 Jun 2025 12:53:21 +0530 Subject: [PATCH 08/11] fix formating --- services/code.service.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/services/code.service.js b/services/code.service.js index cbda9f2b..75ff9ea1 100644 --- a/services/code.service.js +++ b/services/code.service.js @@ -1,4 +1,3 @@ - /* globals gc */ const util = require('util') const exec = util.promisify(require('child_process').exec) @@ -272,12 +271,10 @@ const _executeCode = async (req, res, response) => { outputLog.error !== undefined ? _prepareErrorMessage(outputLog, language, command) : outputLog.result.stdout - if (outputLog.error) { response.error = 1 } - } - else { + } else { response.error = 1 } } catch (e) { @@ -425,7 +422,7 @@ const _getAiScore = async (langConfig, question, response, points, userAnswer, r const _executeStatement = (db, sql) => { return new Promise((resolve, reject) => { - db.all(sql, function (err, rows) { + db.all(sql, function(err, rows) { if (err) { reject(err); } else { @@ -890,7 +887,7 @@ const _checkIntegrity = async (non_editable_files) => { const fullPath = path.join(appConfig.multifile.workingDir, filePath) const fileContent = await fs.promises.readFile(fullPath) const actualHash = crypto.createHash('sha256').update(fileContent).digest('hex') - if (actualHash !== expectedHash) { + if(actualHash !== expectedHash) { logger.warn(`Integrity check failed for file: ${filePath}`) return false } @@ -913,14 +910,14 @@ const _postCleanUp = async (type, staticServerInstance = undefined, jasmineServe await _cleanUpDir(appConfig.multifile.workingDir, appConfig.multifile.submissionFileDownloadPath) switch (type) { case FRONTEND_STATIC_JASMINE: - if (staticServerInstance) { + if(staticServerInstance) { staticServerInstance.close(() => { logger.info('Exiting static server in post cleanup') }) } break case FRONTEND_REACT_JASMINE: - if (jasmineServer) { + if(jasmineServer) { logger.info('Exiting react setup server in post cleanup') process.kill(-jasmineServer.pid) } From d79e0d6031f84fe6dcb79c4ed0e9553d2b2fa72d Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Tue, 17 Jun 2025 12:56:41 +0530 Subject: [PATCH 09/11] fix formating --- services/code.service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/code.service.js b/services/code.service.js index 75ff9ea1..fa53932a 100644 --- a/services/code.service.js +++ b/services/code.service.js @@ -887,7 +887,7 @@ const _checkIntegrity = async (non_editable_files) => { const fullPath = path.join(appConfig.multifile.workingDir, filePath) const fileContent = await fs.promises.readFile(fullPath) const actualHash = crypto.createHash('sha256').update(fileContent).digest('hex') - if(actualHash !== expectedHash) { + if (actualHash !== expectedHash) { logger.warn(`Integrity check failed for file: ${filePath}`) return false } @@ -940,7 +940,7 @@ const _executeMultiFile = async (req, res, response) => { let result if (req?.non_editable_files) { const isValidSubmission = await _checkIntegrity(req.non_editable_files) - if (!isValidSubmission) throw new Error(`A non editable file has been modified, exiting...`) + if(!isValidSubmission) throw new Error(`A non editable file has been modified, exiting...`) } switch (req.type) { case FRONTEND_STATIC_JASMINE: From 3da18926a2368101917084be7e37d9b693c34a1d Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Tue, 17 Jun 2025 13:09:54 +0530 Subject: [PATCH 10/11] feat: improve memory usage logging formate --- services/code.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/code.service.js b/services/code.service.js index fa53932a..24df55cb 100644 --- a/services/code.service.js +++ b/services/code.service.js @@ -265,7 +265,7 @@ const _executeCode = async (req, res, response) => { response.memory = null; } - console.log('Memory used:', response.memory); + logger.info(`Memory usage for ${language} code execution: ${response.memory} KB`); response.output = outputLog.error !== undefined From 97a52af31a09a4537b9b99952aa8fe1f267ef9d3 Mon Sep 17 00:00:00 2001 From: Abhinav Prajapati Date: Tue, 17 Jun 2025 13:31:42 +0530 Subject: [PATCH 11/11] fix: replace console.error with logger.error for memory report read failure --- services/code.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/code.service.js b/services/code.service.js index 24df55cb..41ee4dba 100644 --- a/services/code.service.js +++ b/services/code.service.js @@ -254,7 +254,7 @@ const _executeCode = async (req, res, response) => { const memoryReport = await fs.promises.readFile(memoryReportPath, 'utf8') memoryKB = parseInt(memoryReport.trim(), 10) } catch (err) { - console.error(`Memory report not found or failed to read: ${err.message}`) + logger.error(`Memory report not found or failed to read: ${err.message}`) } const isAlpine = fs.existsSync('/etc/alpine-release');