Skip to content

Commit

Permalink
Fixed an issue that caused the same block of files to be requested mu…
Browse files Browse the repository at this point in the history
…ltiple times at a very high rate. This caused the TCP layer to run out of resources and stall, causing the WDT to trip.
  • Loading branch information
MartinMueller2003 committed Dec 18, 2023
1 parent f7533de commit 4089791
Showing 1 changed file with 53 additions and 46 deletions.
99 changes: 53 additions & 46 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,18 +512,22 @@ function RequestListOfFiles(StartingFileIndex) {
ExpectedStartingFileIndex = StartingFileIndex;

// is the timer running?
if (null === FseqFileListRequestTimer) {
if (null === FseqFileListRequestTimer)
{
// console.info("RequestStatusUpdate: Starting new timer");
// timer runs until we get a response
FseqFileListRequestTimer = setTimeout(function () {
// console.info("Retrying with index: " + StartingFileIndex);

clearTimeout(FseqFileListRequestTimer);
FseqFileListRequestTimer = null;

RequestListOfFiles(StartingFileIndex);

}, 1000);
}, 5000);
} // end timer was not running

// ask for a file list from the server
// console.info("ask for a file list from the server, starting at " + StartingFileIndex);

return fetch("HTTP://" + target + "/files/" + StartingFileIndex, {
method: 'GET',
Expand All @@ -539,7 +543,7 @@ function RequestListOfFiles(StartingFileIndex) {
const isJson = webResponse.headers.get('content-type')?.includes('application/json');
const data = isJson && await webResponse.json();

// console.info("SendCommand:webResponse.status: " + webResponse.status);
console.info("SendCommand:webResponse.status: " + webResponse.status);
// console.info("SendCommand:webResponse.ok: " + webResponse.ok);
// check for error response
if (!webResponse.ok) {
Expand All @@ -550,10 +554,12 @@ function RequestListOfFiles(StartingFileIndex) {
else
{
// console.info("SendCommand: Transaction complete");

clearTimeout(FseqFileListRequestTimer);
FseqFileListRequestTimer = null;
ProcessGetFileListResponse(data);

CompletedServerTransaction = true;
ProcessGetFileListResponse(data);
}
return webResponse.ok ? 1 : 0;
})
Expand Down Expand Up @@ -584,55 +590,56 @@ function ProcessGetFileListResponse(JsonConfigData) {
$("#usedBytes").val(BytesToMB(JsonConfigData.usedBytes));
$("#remainingBytes").val(BytesToMB(JsonConfigData.totalBytes - JsonConfigData.usedBytes));

Fseq_File_List = JsonConfigData;

clearTimeout(FseqFileListRequestTimer);
FseqFileListRequestTimer = null;
// console.info("Expected File Index: " + ExpectedStartingFileIndex);
// console.info("Received File index: " + JsonConfigData.first);

// are we starting a fresh list (first chunk)
if(JsonConfigData.first === 0)
if(ExpectedStartingFileIndex === JsonConfigData.first)
{
// console.info("$('#FileManagementTable > tr').length " + $('#FileManagementTable > tr').length);
// are we starting a fresh list (first chunk)
if(JsonConfigData.first === 0)
{
// console.info("$('#FileManagementTable > tr').length " + $('#FileManagementTable > tr').length);
Fseq_File_List = [];

while (1 < $('#FileManagementTable > tr').length) {
// console.info("Deleting $('#FileManagementTable tr').length " + $('#FileManagementTable tr').length);
$('#FileManagementTable tr').last().remove();
// console.log("After Delete: $('#FileManagementTable tr').length " + $('#FileManagementTable tr').length);
while (1 < $('#FileManagementTable > tr').length) {
// console.info("Deleting $('#FileManagementTable tr').length " + $('#FileManagementTable tr').length);
$('#FileManagementTable tr').last().remove();
// console.log("After Delete: $('#FileManagementTable tr').length " + $('#FileManagementTable tr').length);
}
}
}

console.info("Expected File Index: " + ExpectedStartingFileIndex);
console.info("Received File index: " + JsonConfigData.first);

JsonConfigData.files.forEach(function (file) {
let CurrentRowId = $('#FileManagementTable > tr').length;
let SelectedPattern = '<td><input type="checkbox" id="FileSelected_' + (CurrentRowId) + '"></td>';
let NamePattern = '<td><output type="text" id="FileName_' + (CurrentRowId) + '"></td>';
let DatePattern = '<td><output type="text" id="FileDate_' + (CurrentRowId) + '"></td>';
let SizePattern = '<td><output type="text" id="FileSize_' + (CurrentRowId) + '"></td>';

let rowPattern = '<tr>' + SelectedPattern + NamePattern + DatePattern + SizePattern + '</tr>';
$('#FileManagementTable tr:last').after(rowPattern);
JsonConfigData.files.forEach(function (file) {
let CurrentRowId = $('#FileManagementTable > tr').length;
let SelectedPattern = '<td><input type="checkbox" id="FileSelected_' + (CurrentRowId) + '"></td>';
let NamePattern = '<td><output type="text" id="FileName_' + (CurrentRowId) + '"></td>';
let DatePattern = '<td><output type="text" id="FileDate_' + (CurrentRowId) + '"></td>';
let SizePattern = '<td><output type="text" id="FileSize_' + (CurrentRowId) + '"></td>';

let rowPattern = '<tr>' + SelectedPattern + NamePattern + DatePattern + SizePattern + '</tr>';
$('#FileManagementTable tr:last').after(rowPattern);

try {
$('#FileName_' + (CurrentRowId)).val(file.name);
$('#FileDate_' + (CurrentRowId)).val(new Date(file.date * 1000).toLocaleString());
$('#FileSize_' + (CurrentRowId)).val(file.length);
Fseq_File_List.push(file);
}
catch
{
$('#FileName_' + (CurrentRowId)).val("InvalidFile");
$('#FileDate_' + (CurrentRowId)).val(new Date(0).toISOString());
$('#FileSize_' + (CurrentRowId)).val(0);
}
}); // end foreach

try {
$('#FileName_' + (CurrentRowId)).val(file.name);
$('#FileDate_' + (CurrentRowId)).val(new Date(file.date * 1000).toLocaleString());
$('#FileSize_' + (CurrentRowId)).val(file.length);
}
catch
// was this the last chunk?
if(false === JsonConfigData.final)
{
$('#FileName_' + (CurrentRowId)).val("InvalidFile");
$('#FileDate_' + (CurrentRowId)).val(new Date(0).toISOString());
$('#FileSize_' + (CurrentRowId)).val(0);
// console.info("not last. Ask for the next chunk");
RequestListOfFiles(JsonConfigData.last);
}
}); // end foreach
} // end expected file ID

// was this the last chunk?
if(false === JsonConfigData.final)
{
// not last. Ask for the next chunk
RequestListOfFiles(JsonConfigData.last);
}
} // ProcessGetFileListResponse

function RequestFileDeletion() {
Expand Down Expand Up @@ -663,7 +670,7 @@ function ProcessModeConfigurationDatafppremote(channelConfig) {
$(jqSelector).append('<option value="...">Play Remote Sequence</option>');

// for each file in the list
Fseq_File_List.files.forEach(function (listEntry) {
Fseq_File_List.forEach(function (listEntry) {
// add in a new entry
$(jqSelector).append('<option value="' + listEntry.name + '">' + listEntry.name + '</option>');
});
Expand Down

0 comments on commit 4089791

Please sign in to comment.