Headless Client shutdown

It’s not working with application.exit().

I receive on the callback

JSEvent(type = headlessExceptionCallback …

and also in the log I can see:

Error calling method generateInvoicesForFlight, context: null on client FC69E03D-4DC8-470E-A806-C19C6B3D48CA

, which is quite strange because this is the method in the headless client that is executed:

function generateInvoicesForFlight(userLoginId, flightId, invoiceOnSave) {
	if (!globals.userLogin(userLoginId)) {
		return;
	}

	globals.databaseStartTransaction();
	forms.commons_logbook.generateInvoices(flightId, invoiceOnSave);
	globals.databaseCommit();

	application.exit();
}

Removing application.exit(); from the end will make things work. But the client remains open.

Any other solution? Btw, I’m using Servoy 5.2. Please don’t ask me to switch to a newer one…