Skip to content

Commit 704ecc3

Browse files
committed
Guard against workflow background happening early
Fixes #6756 because the ringbuf size is zero and the empty check does % which leads to division by zero error.
1 parent da5c0cc commit 704ecc3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

supervisor/shared/web_workflow/websocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void websocket_handoff(socketpool_socket_obj_t *socket) {
7878
}
7979

8080
bool websocket_connected(void) {
81-
return !cp_serial.closed && common_hal_socketpool_socket_get_connected(&cp_serial.socket);
81+
return _incoming_ringbuf.size > 0 && !cp_serial.closed && common_hal_socketpool_socket_get_connected(&cp_serial.socket);
8282
}
8383

8484
static bool _read_byte(uint8_t *c) {

supervisor/shared/workflow.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
#endif
4747
static background_callback_t workflow_background_cb;
4848

49+
static bool workflow_started = false;
50+
4951
static void workflow_background(void *data) {
5052
#if CIRCUITPY_WEB_WORKFLOW
5153
supervisor_web_workflow_background();
@@ -68,6 +70,9 @@ void supervisor_workflow_reset(void) {
6870
}
6971

7072
void supervisor_workflow_request_background(void) {
73+
if (!workflow_started) {
74+
return;
75+
}
7176
background_callback_add_core(&workflow_background_cb);
7277
}
7378

@@ -114,4 +119,6 @@ void supervisor_workflow_start(void) {
114119
#if CIRCUITPY_WEB_WORKFLOW
115120
supervisor_start_web_workflow();
116121
#endif
122+
123+
workflow_started = true;
117124
}

0 commit comments

Comments
 (0)