Skip to content

Commit

Permalink
update museumsvictoria#278: safety: console line length cap to 500 ch…
Browse files Browse the repository at this point in the history
…ars.
  • Loading branch information
Justin Parker committed Jan 24, 2023
1 parent 96c81cf commit 97f0ea7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion nodel-framework/src/main/java/org/nodel/host/BaseNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,29 @@ public List<ConsoleLogEntry> getConsoleLogs(@Param(name = "from", title = "From"
return batch;
}
} // (method)

/**
* FUTURE WORK: a host parameter might control this length i.e. "maxConsoleLineLength"
* 500 is probably is safe likely practical limit.
*/
private final static int MAX_CONSOLE_LINELENGTH = 500;

/**
* Adds to the console logs, dropping if necessary.
*/
protected void addConsoleLog(DateTime timestamp, ConsoleLogEntry.Console console, String line) {
// don't allow excessively long console lines. Prevents accidental memory consumption
if (line != null && line.length() > MAX_CONSOLE_LINELENGTH) {
int len = line.length();
line = line.substring(0, len-4) + "...";
}

// FUTURE WORK: the console activity could be added as a Diagnostics chart to show up the existence
// of excessive console thrashing or memory use.

synchronized(_console) {
// stamp with current sequence number
ConsoleLogEntry entry = new ConsoleLogEntry(_consoleSeqCounter++, timestamp, console, line);
ConsoleLogEntry entry = new ConsoleLogEntry(_consoleSeqCounter++, timestamp, console, line);

_console.add(entry);

Expand Down

0 comments on commit 97f0ea7

Please sign in to comment.