From 2eb89fa06207c7cd2380ba4efbf6754ceff9e415 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Thu, 12 Feb 2026 07:47:18 +1100 Subject: [PATCH] Fix Bug #3637: Fix internal crash when WebSocket initialisation fails in monitor mode (#3639) This PR fixes an internal crash in --monitor mode when WebSocket (Socket.IO) initialisation fails (for example, when Microsoft Graph returns 400 notSupported). Previously, a failed WebSocket initialisation could leave the internal oneDriveSocketIo object unset (null), while later monitor-loop logic still assumed it was available. This resulted in a null dereference and a SIGSEGV, causing the client to exit after the first monitor loop. --- src/config.d | 7 ++++++- src/main.d | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/config.d b/src/config.d index ad004262..2efa911e 100644 --- a/src/config.d +++ b/src/config.d @@ -1784,11 +1784,16 @@ class ApplicationConfig { addLogEntry(); addLogEntry("--------------------DEVELOPER_OPTIONS----------------------------"); addLogEntry("Config option 'force_children_scan' = " ~ to!string(getValueBool("force_children_scan"))); - addLogEntry(); + addLogEntry("Config option 'monitor_max_loop' = " ~ to!string(getValueLong("monitor_max_loop"))); + addLogEntry("Config option 'display_memory' = " ~ to!string(getValueBool("display_memory"))); + addLogEntry("Config option 'display_sync_options' = " ~ to!string(getValueBool("display_sync_options"))); + addLogEntry("Config option 'display_processing_time' = " ~ to!string(getValueBool("display_processing_time"))); } + // Close out config output if (getValueBool("display_running_config")) { addLogEntry("-----------------------------------------------------------------"); + addLogEntry(); } } diff --git a/src/main.d b/src/main.d index db47d015..93d03bb9 100644 --- a/src/main.d +++ b/src/main.d @@ -1033,6 +1033,8 @@ int main(string[] cliArgs) { addLogEntry("Enabled WebSocket support to monitor Microsoft Graph API changes in near real-time."); } else { addLogEntry("ERROR: Unable to configure WebSocket support to monitor Microsoft Graph API changes in near real-time."); + if (debugLogging) {addLogEntry("Setting 'disable_websocket_support' to 'true' to force WebSockets to be disabled.", ["debug"]);} + appConfig.setValueBool("disable_websocket_support" , true); } } else { // WebSocket Support has been disabled @@ -1403,7 +1405,7 @@ int main(string[] cliArgs) { Duration nextWebhookCheckDuration = oneDriveWebhook.getNextExpirationCheckDuration(); if (nextWebhookCheckDuration < sleepTime) sleepTime = nextWebhookCheckDuration; notificationReceived = false; - } else if (!appConfig.getValueBool("disable_websocket_support") && appConfig.curlSupportsWebSockets) { + } else if (oneDriveSocketIo !is null && !appConfig.getValueBool("disable_websocket_support") && appConfig.curlSupportsWebSockets) { Duration nextWebsocketCheckDuration = oneDriveSocketIo.getNextExpirationCheckDuration(); if (nextWebsocketCheckDuration < sleepTime) sleepTime = nextWebsocketCheckDuration; } @@ -1856,9 +1858,16 @@ extern(C) nothrow @nogc @system void exitViaSignalHandler(int signo) { if (signo == SIGSEGV) { // Was SIGTERM used? if (!sigtermHandlerTriggered) { - // No .. so most likely SIGINT (CTRL-C) - printf("Due to a termination signal, internal processing stopped abruptly. The application will now exit in a unclean manner.\n"); - exit(130); + // No .. so most likely SIGINT (CTRL-C) - lets check + if (signo == SIGINT) { + // Yes - SIGINT was used + printf("Due to a termination signal, internal processing stopped abruptly. The application will now exit in a unclean manner.\n"); + exit(130); + } else { + // Confirmed as SIGSEGV, but not SIGINT and SIGTERM not used + printf("FATAL: Segmentation fault (SIGSEGV). The application encountered an internal error and will now exit in a unclean manner.\n"); + exit(139); + } } else { // High probability of being shutdown by systemd, for example: systemctl --user stop onedrive // Exit in a manner that does not trigger an exit failure in systemd