Skip to content

Commit c0064dc

Browse files
committed
Postpone interacting with the web workflow if a SPI bus is locked
I tested this by fetching a .txt file repeatedly using curl while running the fancy camera demo. (100+ times without failure). I also repeatedly loaded the filesystem view http://.../fs/#/sd/ which worked 10+ times without failure, but does take some time (multiple seconds) to show a listing with a few dozen files. (I suspect there's an accidentally quadratic behavior in oofatfs to stat every file in a directory, because it repeatedly does a linear search of the directory for the stat information of each file, but that's not an issue for Right Now(TM)) Closes: #8980
1 parent cbdaaea commit c0064dc

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
#include "shared-bindings/hashlib/Hash.h"
5555
#include "lib/oofatfs/diskio.h"
5656

57+
#if CIRCUITPY_FOURWIRE
58+
#include "shared-module/displayio/__init__.h"
59+
#endif
60+
5761
#if CIRCUITPY_MDNS
5862
#include "shared-bindings/mdns/RemoteService.h"
5963
#include "shared-bindings/mdns/Server.h"
@@ -1559,9 +1563,32 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request)
15591563
}
15601564
}
15611565

1566+
static bool supervisor_filesystem_access_could_block(void) {
1567+
#if CIRCUITPY_FOURWIRE
1568+
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
1569+
if (!vfs->next) {
1570+
// Assume that the CIRCUITPY root is not sharing a SPI bus with the display SPI bus
1571+
return false;
1572+
}
1573+
// Check display 0 to see if it's on a fourwire (SPI) bus. If it is, blocking is possible
1574+
// in theory other displays could block but also in reality there's generally 0 or 1 displays
1575+
for (size_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
1576+
if (display_buses[i].bus_base.type != &fourwire_fourwire_type) {
1577+
continue;
1578+
}
1579+
if (!common_hal_fourwire_fourwire_bus_free(MP_OBJ_FROM_PTR(&display_buses[i].bus_base))) {
1580+
return true;
1581+
}
1582+
}
1583+
#endif
1584+
return false;
1585+
}
15621586

15631587
void supervisor_web_workflow_background(void *data) {
1564-
while (true) {
1588+
// If "/sd" is mounted AND shared with a display, access could block.
1589+
// We don't have a good way to defer a filesystem action way down inside _process_request
1590+
// when this happens, so just postpone if there's a chance of blocking. (#8980)
1591+
while (!supervisor_filesystem_access_could_block()) {
15651592
// If we have a request in progress, continue working on it. Do this first
15661593
// so that we can accept another socket after finishing this request.
15671594
if (common_hal_socketpool_socket_get_connected(&active)) {

0 commit comments

Comments
 (0)