Undesired data scrambling in received CAN frames

I am using CAN.h by Thomas Barth to transmit and receive CAN frames. The board on which I am testing is a custom board with a ESP32 WROOM.

The issue is that once every 5 - 8 frames I am receiving a CAN frame in which the data is completely misplaced (there is no set pattern between different incorrect frames). The data is not being corrupted, it is just being misplaced. Like data that is supposed to be in the first byte turns up in the 8th or 3rd byte.

The program structure is as follows: There is a task with priority 5 which contains a user-defined function inside infinite for loop. Inside the user-defined function i have called xQueueReceive. If there is an item in queue it is copied to a CAN_frame_t variable. That is all. I have tried varying the task delays and transmit delays.

What am I missing here? Is there any tweaking required?

(If the issue is unclear or require any info please do ask)

Does the CAN work when FreeRTOS isn’t used?

How are you receiving CAN data? Using interrupts? Polling? DMA?

What is the queue holding? The received CAN data? If so, how is it written to the queue? Inside an interrupt?

we need to some some code, Evertything else would be like staring into a crystal ball…