Fix synchronization issue during message publishing and queuing.