Error MessageHandlerManager is null in ScriptConfig!

I have a module with a ProjectListener.
on Project update I send a gateway message handled by a gateway script message handler

@Override
public void projectUpdated(String project) {
	if (enabled && filterProjectUpdated) {
		logger.debug("projectUpdated : {}",project);
		if (passFiterProjectNames(project)){
			notifyGateway(project,"projectUpdated");
		}
	}
}

private void notifyGateway(String project,String cause){
	try {
		synchronized(this) {
			String resultGatewayMessageProjectName;

			if (shutdownPending) {
				return;
			}

			if (projectListenerUseGatewayScriptingProject) {
				resultGatewayMessageProjectName = context.getSystemProperties().getGatewayScriptingProject();
			} else {
				if (gatewayMessageProjectName == null) {
					gatewayMessageProjectName = "";
				}
				resultGatewayMessageProjectName = gatewayMessageProjectName;
			}
			if (gatewayMessageHandler == null) {
				gatewayMessageHandler = "";
			}
			if (gatewayMessageHandler.isEmpty()) {
				logger.warn("notifyGateway() - Gateway Notification Enabled but Gateway Message Handler is not provided !");
			} else if (resultGatewayMessageProjectName.isEmpty()) {
				logger.warn("notifyGateway() - Gateway Notification Enabled but Gateway Project Name is not provided !");
			} else {
				PyDictionary messagePayload = new PyDictionary();
				messagePayload.put(new PyString("project"), project);
				messagePayload.put(new PyString("cause"), cause);
				Properties filterParams = new Properties();
				filterParams.setProperty(MessageDispatchManager.KEY_SCOPE, MessageDispatchManager.SCOPE_GATEWAY_ONLY);
				logger.debug("notifyGateway() - Gateway Notification : projectName={}, gatewayMessageHandler={}, messagePayload={}",
						resultGatewayMessageProjectName, gatewayMessageHandler, messagePayload);
				context.getMessageDispatchManager().dispatch(resultGatewayMessageProjectName, gatewayMessageHandler, messagePayload, filterParams);
			}
		}
	} catch (Exception e) {
		logger.error("notifyGateway() - exception : ", e);
	}
}

when I import a project (containing the script executed by the gateway message handler)
I've sometimes have the following error, and as a side effect it seems that all tags expression with runscript are broken...and I need to restart the gateway

You are racing with the Project Script Manager, which also listens for project changes in order to restart script modules. You simply should not be generating this message. A project script can tell when its underlying project starts up by implementing a startup event. That will always fire in a non-racy way.

Some things are not meant to be done by SDK modules.

I Believe that the startup script was fired each time some change are saved in scripts.
I want to process only on project import.
Perhaps I could add a delay before sending the gateway message. Not a good way to make some synchonization but a workaround...

How are you determining this? Diving into project change diffs?

I import a global common project inherited by another one, and according to some settings (features activated or not) I delete unusefull code.py files and run a project rescan.