From 21bdef01eddcbd78044eea1d50b9dee08d218ff2 Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Thu, 29 Aug 2024 12:45:45 -0400 Subject: [PATCH] Check the primary connection and assume primary if no response is found. This guards against the case of stale shared memory that can happen when the primary application crashes or is forcefully killed. Issue #190 Signed-off-by: Adam Treat --- singleapplication.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/singleapplication.cpp b/singleapplication.cpp index 95c4d18..d676871 100644 --- a/singleapplication.cpp +++ b/singleapplication.cpp @@ -137,6 +137,13 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda } } + // Check to ensure the primary process really does exist by sending a message and if it does not + // then assume primary status + if ( inst->primary != false && !d->connectToPrimary( timeout, SingleApplicationPrivate::SecondaryInstance )) { + qDebug() << "SingleApplication: Cannot communicate with primary so assuming primary status."; + inst->primary = false; + } + if( inst->primary == false ){ d->startPrimary(); if( ! d->memory->unlock() ){