Hang on RIL_MQTT_QMTPUB in Ql_Mqtt_Recv_Register's Function (RIL Task)

I’m working on a M66 device that connects to a thingsboard server and apart from publishing sensor values to server (over MQTT), it subscribes to a RPC Topic.

As you know RPC Commands gets published at a topic with a specific ID at end; device gets it and after processing, have to publish result in another topic (if need).
Publishing data over MQTT worked with no problem, so I register a MQTT receive callback function at the main task to achieve RPC Commands (I test registering in another task, no difference):

// Register MQTT recv callback

then in MqttReceiveHandler, I call another function named ProccesMqttRPC and at the end of it, I call RIL_MQTT_QMTPUB as like below, but it cause to hang:

ret = RIL_MQTT_QMTPUB(ConnectID_0, 0,
                      QOS0_AT_MOST_ONECE, 0, Topic,
                      Ql_strlen(JsonTempBegin2), JsonTempBegin2);

I Trace it, Hang cause when Ql_RIL_SendATCmd called in ril_mqtt.c…

I was very confused but tracing tasks realize me that publishing sensor values executes from the main task but publishing RPC Results executes from the Task 2 (proc_reserved1 = RIL)! As I mentioned, I test registering in another task, no difference to executing task…

so is it mean that we can’t publish from RIL tasks? what to do then if we want to publish when some data arrives?

From my point of view, I will set a small task with a higher priority than the main task to monitor the MQTT data. When the data I need comes, I will notify the main task to suspend, and then skip to the secondary task that operates the MQTT data. This does not require you to adjust the priority of the secondary task, but just set up a high-priority task with a small workload. Using the messaging mechanism may help you solve the problem better. Good luck