BluetoothSerial locks up after receiving 512 bytes

I'm using ESP32 and bluetooth to communicate with my Android phone. The program on the phone is created using MIT App Inventor.
When I'm sending long strings (containing JSON) fom ESP32 to the phone, all goes well, regardless how long the string is. When I'm sending long strings from the phone to ESP32, the Bluetooth Serial reception locks up after receiving 512 bytes.
Whenever the ESP_SPP_DATA_IND_EVT event occurs, I'm reading the entire input buffer using

while (SerialBT.available()) { // do this until all chars have been consumed
c =;
if(btIncomingIndex < (SIZE_BT_INCOMING - 2)) { // if char buffer not full (leave room for terminating '\0')
btIncomingChars[btIncomingIndex++] = c; // store the char and increment index
... more code ...
My BT code contains a supervision timer to detect that BT has stopped receiving data for at least 5 seconds before the message is complete. Message completion is detected by counting the opening and closing curly brackets (since all messages are JSON, the message is complete when the count for opening and closing curly brackets is matching). Everything is fine for short messages, but when the message length exceeds 512 bytes BT locks up and my supervision timer fires.
Is this a bug or do I need to take extra steps to receive very long messages?

PS: I'm using the SPP profile on BT Classic

In BluetoothSerial.cpp you will find this line
#define RX_QUEUE_SIZE 512

You can try and make the value larger.

Thank you so much. That fixes the problem.
I increased the size to 2k bytes. Fortunately ESP32 has plenty of RAM.

I'm not a BT expert, but I would expect that the BT sink signals to the BT source to suspend transmission when the RX buffer gets full and to resume sending when the buffer has been read and thus freed for reception of more data. But that doesn't seem to happen. IMHO this is a design flaw in BluetoothSerial.