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

Fixed a race condition in output config processing that causes a crash while processing the config file. #652

Merged
merged 4 commits into from
Aug 22, 2023
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
19 changes: 18 additions & 1 deletion ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ void c_WebMgr::init ()
}
});

// ping handler
webServer.on ("/files", HTTP_GET | HTTP_OPTIONS, [](AsyncWebServerRequest* request)
{
// DEBUG_V("files");
Expand All @@ -259,6 +258,24 @@ void c_WebMgr::init ()
}
});

webServer.on ("/file/delete", HTTP_POST | HTTP_OPTIONS, [](AsyncWebServerRequest* request)
{
// DEBUG_V("/file/delete");
// DEBUG_V(String("URL: ") + request->url());
if(HTTP_OPTIONS == request->method())
{
request->send (200);
}
else
{
// DEBUG_V (String ("url: ") + String (request->url ()));
String filename = request->url ().substring (String ("/file/delete").length ());
// DEBUG_V (String ("filename: ") + String (filename));
FileMgr.DeleteSdFile(filename);
request->send (200);
}
});

// JSON Config Handler
webServer.on ("/conf", HTTP_PUT | HTTP_POST | HTTP_OPTIONS,
[this](AsyncWebServerRequest* request)
Expand Down
30 changes: 20 additions & 10 deletions ESPixelStick/src/output/OutputMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ void c_OutputMgr::Begin ()

// CreateNewConfig ();

// load up the configuration from the saved file. This also starts the drivers
// DEBUG_V();
// DEBUG_V("load up the configuration from the saved file. This also starts the drivers");
LoadConfig();

// CreateNewConfig ();
Expand Down Expand Up @@ -1003,6 +1002,9 @@ void c_OutputMgr::LoadConfig ()
{
// DEBUG_START;

ConfigLoadNeeded = false;
ConfigInProgress = true;

// try to load and process the config file
if (!FileMgr.LoadConfigFile(ConfigFileName, [this](DynamicJsonDocument &JsonConfigDoc)
{
Expand Down Expand Up @@ -1032,6 +1034,8 @@ void c_OutputMgr::LoadConfig ()
}
}

ConfigInProgress = false;

// DEBUG_END;

} // LoadConfig
Expand Down Expand Up @@ -1290,11 +1294,10 @@ void c_OutputMgr::Poll()
// do we need to save the current config?
if (true == ConfigLoadNeeded)
{
ConfigLoadNeeded = false;
LoadConfig ();
} // done need to save the current config

if (false == IsOutputPaused)
if ((false == IsOutputPaused) && (false == ConfigInProgress))
{
// //DEBUG_V();
for (DriverInfo_t & OutputChannel : OutputChannelDrivers)
Expand All @@ -1318,23 +1321,30 @@ void c_OutputMgr::TaskPoll()
// do we need to save the current config?
if (true == ConfigLoadNeeded)
{
ConfigLoadNeeded = false;
// DEBUG_V("Starting config processing");
LoadConfig ();
// DEBUG_V("Done config processing");
} // done need to save the current config

if (false == IsOutputPaused)
if ((false == IsOutputPaused) && (false == ConfigInProgress))
{
// PollCount ++;
bool FoundAnActiveOutputChannel = false;
// //DEBUG_V();
for (DriverInfo_t & OutputChannel : OutputChannelDrivers)
{
// //DEBUG_V("Start a new channel");
uint32_t DelayInUs = OutputChannel.pOutputChannelDriver->Poll ();

if(DelayInUs)
if(nullptr != OutputChannel.pOutputChannelDriver)
{
uint32_t DelayInUs = OutputChannel.pOutputChannelDriver->Poll ();
if(DelayInUs)
{
FoundAnActiveOutputChannel = true;
}
}
else
{
FoundAnActiveOutputChannel = true;
// DEBUG_V(String("Missing pOutputChannelDriver for channel: ") + String(OutputChannel.DriverId));
}
}

Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/output/OutputMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class c_OutputMgr

bool HasBeenInitialized = false;
bool ConfigLoadNeeded = false;
bool ConfigInProgress = false;
bool IsOutputPaused = false;
bool BuildingNewConfig = false;

Expand Down
11 changes: 6 additions & 5 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ function RequestListOfFiles() {
else
{
// console.info("SendCommand: Transaction complete");
clearTimeout(FseqFileListRequestTimer);
FseqFileListRequestTimer = null;
ProcessGetFileListResponse(data);
CompletedServerTransaction = true;
}
Expand Down Expand Up @@ -619,17 +621,16 @@ function ProcessGetFileListResponse(JsonConfigData) {
} // ProcessGetFileListResponse

function RequestFileDeletion() {
let files = [];

$('#FileManagementTable > tr').each(function (CurRowId) {
if (true === $('#FileSelected_' + CurRowId).prop("checked")) {
let FileEntry = {};
FileEntry["name"] = $('#FileName_' + CurRowId).val().toString();
files.push(FileEntry);
let name = $('#FileName_' + CurRowId).val().toString();
console.info("delete file: " + name);
let Response = SendCommand('file/delete/' + name);
// console.info("delete Response: " + Response);
}
});

// TOBERESTORED wsEnqueue(JSON.stringify({ 'cmd': { 'delete': { 'files': files } } }));
RequestListOfFiles();

} // RequestFileDeletion
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ build_flags = ${esp32.build_flags} -mtext-section-literals
; platform = https://github.com/platformio/platform-espressif32.git#eb7eba4 ; unstable 6.3.2
platform = https://github.com/platformio/platform-espressif32.git#8100ac5 ; works 6.3.1
platform_packages =
; framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.11 ;
; framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.11 ; uses a lot of ram
framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.3 ;
; framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.2 ; runs real slow
; framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.1 ; Has general issues
Expand Down