Skip to content

Commit

Permalink
(fix) handle EAS termination when SOGo is being shutdown (fixes #3604)
Browse files Browse the repository at this point in the history
Conflicts:

	ActiveSync/SOGoActiveSyncDispatcher.m
  • Loading branch information
extrafu committed Mar 29, 2016
1 parent 5a2676f commit 44d8b63
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion ActiveSync/SOGoActiveSyncDispatcher+Sync.m
Expand Up @@ -1905,6 +1905,9 @@ - (void) processSync: (id <DOMElement>) theDocumentElement
// We enter our loop detection change
for (i = 0; i < (heartbeatInterval/internalInterval); i++)
{
if (shouldTerminate)
break;

s = [NSMutableString string];

for (j = 0; j < [allCollections count]; j++)
Expand Down Expand Up @@ -1944,7 +1947,7 @@ - (void) processSync: (id <DOMElement>) theDocumentElement
{
total_sleep = 0;

while (total_sleep < internalInterval)
while (!shouldTerminate && total_sleep < internalInterval)
{
// We check if we must break the current synchronization since an other Sync
// has just arrived.
Expand Down
3 changes: 2 additions & 1 deletion ActiveSync/SOGoActiveSyncDispatcher.h
Expand Up @@ -37,14 +37,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@class NSURL;
@class NSNumber;

static volatile BOOL shouldTerminate = NO;

@interface SOGoActiveSyncDispatcher : NSObject
{
NSURL *folderTableURL;
NSDictionary *imapFolderGUIDS;
id context;

NSNumber *syncRequest;

BOOL debugOn;
}

Expand Down
17 changes: 16 additions & 1 deletion ActiveSync/SOGoActiveSyncDispatcher.m
Expand Up @@ -52,6 +52,7 @@
#import <NGObjWeb/WODirectAction.h>
#import <NGObjWeb/WORequest.h>
#import <NGObjWeb/WOResponse.h>
#import <NGObjWeb/WOCoreApplication.h>

#import <NGCards/iCalCalendar.h>
#import <NGCards/iCalEntityObject.h>
Expand Down Expand Up @@ -144,6 +145,13 @@
#include <openssl/x509.h>
#endif

void handle_terminate(int signum)
{
NSLog(@"Forcing termination of EAS loop.");
shouldTerminate = YES;
[[WOCoreApplication application] terminateAfterTimeInterval: 1];
}

@interface SOGoActiveSyncDispatcher (Sync)

- (NSMutableDictionary *) _folderMetadataForKey: (NSString *) theFolderKey;
Expand All @@ -161,6 +169,10 @@ - (id) init
folderTableURL = nil;
imapFolderGUIDS = nil;
syncRequest = nil;

shouldTerminate = NO;
signal(SIGTERM, handle_terminate);

return self;
}

Expand Down Expand Up @@ -2098,6 +2110,9 @@ - (void) processPing: (id <DOMElement>) theDocumentElement
// We enter our loop detection change
for (i = 0; i < (heartbeatInterval/internalInterval); i++)
{
if (shouldTerminate)
break;

pool = [[NSAutoreleasePool alloc] init];
for (j = 0; j < [allFoldersID count]; j++)
{
Expand Down Expand Up @@ -2135,7 +2150,7 @@ - (void) processPing: (id <DOMElement>) theDocumentElement
{
total_sleep = 0;

while (total_sleep < internalInterval)
while (!shouldTerminate && total_sleep < internalInterval)
{
// We check if we must break the current ping request since an other ping request
// has just arrived.
Expand Down

0 comments on commit 44d8b63

Please sign in to comment.