# CoreMQTT: Can't find where the network buffer gets allocated

**URL:** <https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829>\
**Category:** Libraries\
**Created:** [April 18, 2024, 8:21am UTC](https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829 "2024-04-18T08:21:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dyfan](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Dyfan](https://forums.freertos.org/u/Dyfan)\
**Post date:** [April 18, 2024, 8:21am UTC](https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829/1 "2024-04-18T08:21:17Z")

</div>

Hello FreeRTOS Forums!

I’m playing around with the message size in MQTT, (seeing if I can send large messages 2GB ish) and the error I’m facing is that the assert:

assert( pContext-\>networkBuffer.pBuffer != NULL );

get called. I’ve struggles to see where this is allocated, any tips and that would really help.

See below snippet for exactly where the assert is from.

static MQTTStatus\_t receivePacket( const MQTTContext\_t \* pContext,  
MQTTPacketInfo\_t incomingPacket,  
uint32\_t remainingTimeMs )  
{  
MQTTStatus\_t status = MQTTSuccess;  
int32\_t bytesReceived = 0;  
size\_t bytesToReceive = 0U;

```
assert( pContext != NULL );
assert( pContext->networkBuffer.pBuffer != NULL );

```

Kind regards,  
Dyfan

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [April 18, 2024, 8:46am UTC](https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829/2 "2024-04-18T08:46:13Z")

</div>

@Dyfan

The network buffer gets initialized/allocated to the `MQTTContext_t` during the `MQTT_Init` call. For example, in the case of [MQTT\_Mutual\_Auth](https://github.com/FreeRTOS/FreeRTOS/tree/main/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth) demo it’s done [here](https://github.com/FreeRTOS/FreeRTOS/blob/2023ac64043a05839cdffaa752eff693fb26e6a6/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth/DemoTasks/MutualAuthMQTTExample.c#L796).

In this case, the network buffer is statically allocated [here](https://github.com/FreeRTOS/FreeRTOS/blob/2023ac64043a05839cdffaa752eff693fb26e6a6/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth/DemoTasks/MutualAuthMQTTExample.c#L481).

---

<div class="post-metadata">

**Author:** ![Dyfan](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Dyfan](https://forums.freertos.org/u/Dyfan)\
**Post date:** [April 18, 2024, 4:09pm UTC](https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829/3 "2024-04-18T16:09:39Z")

</div>

@tony-josi-aws

Thanks for the speedy reply!

If I wanted to increase the MQTT messages that are received on the micrcontroller end, about 2GB would I have to increase this buffer and ipconfigTCP\_RX\_BUFFER\_LENGTH to 2G?

Cheers!

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [April 18, 2024, 4:29pm UTC](https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829/4 "2024-04-18T16:29:45Z")

</div>

@Dyfan

The `ipconfigTCP_RX_BUFFER_LENGTH` sets the size of the circular stream buffer for the TCP data reception used by the FreeRTOS+TCP stack. Its value can be set depending on how much RAM you have on your device; its default value, if not overridden in FreeRTOSIPConfig.h, is `( 4 * ipconfigTCP_MSS )`.

Theoretically this should be the maximum size you could expect to receive from the `FreeRTOS_recv`. If you are increasing `ipconfigTCP_RX_BUFFER_LENGTH` please make sure to increase the size of the network buffer thats given to the `MQTT_Init`, `democonfigNETWORK_BUFFER_SIZE` in the example referred above.

---

<div class="post-metadata">

**Author:** ![Dyfan](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Dyfan](https://forums.freertos.org/u/Dyfan)\
**Post date:** [April 18, 2024, 4:51pm UTC](https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829/5 "2024-04-18T16:51:18Z")

</div>

@tony-josi-aws

Having increased both to 2GB about 11300 comes through, is there any other variables that need increasing?

---

<div class="post-metadata">

**Author:** ![cobusve](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/cobusve/32/1447_2.png) [@cobusve](https://forums.freertos.org/u/cobusve)\
**Post date:** [April 18, 2024, 7:09pm UTC](https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829/6 "2024-04-18T19:09:00Z")

</div>

Are you trying to send or receive messages? Your question says you are trying to send but the snippets are referring to receiving messages?

If you are receiving the packet I would suggest you set a breakpoint [here](https://github.com/FreeRTOS/coreMQTT/blob/main/source/core_mqtt.c#L1189) where the packet is incoming, and then step through and see where it is failing. With that much data you are probably ending up timing out somewhere and not running out of space.

[This line](https://github.com/FreeRTOS/coreMQTT/blob/ce8bb2a9761dbdbd77f5dbf31e16c37782446e7f/source/core_mqtt.c#L1203C25-L1203C35) should be asking for 2GB of data, and as you can see before this you would have generated [an error here](https://github.com/FreeRTOS/coreMQTT/blob/ce8bb2a9761dbdbd77f5dbf31e16c37782446e7f/source/core_mqtt.c#L1189) if you asked for more data than the length of the network buffer (if buffer was too small in other words).

The actual reading of the data happens [on this line](https://github.com/FreeRTOS/coreMQTT/blob/ce8bb2a9761dbdbd77f5dbf31e16c37782446e7f/source/core_mqtt.c#L991), so in your debugger you should be able to follow it from here.

---

<div class="post-metadata">

**Author:** ![Dyfan](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Dyfan](https://forums.freertos.org/u/Dyfan)\
**Post date:** [April 22, 2024, 11:06am UTC](https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829/7 "2024-04-22T11:06:30Z")

</div>

@cobusve I am trying to receive messages. If you could point out where I’m referencing sending messages I’m happy to edit it to make it clearer.

The links that you send me refer to the function receivePacket, however the path that this message come via the receiveSingleIteration. I’m essentially using the plaintext demo code is this where I might be going wrong? should I replace it with receivePacket?

I’ve stepped through the code, and all the variables are as expected but the data is just short. I can’t see any errors being flagged anywhere. Thanks for the previous help and I’ll appreciate anymore suggestions.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [April 22, 2024, 11:59am UTC](https://forums.freertos.org/t/coremqtt-cant-find-where-the-network-buffer-gets-allocated/19829/8 "2024-04-22T11:59:56Z")

</div>

> [@Dyfan](#):
>
> however the path that this message come via the receiveSingleIteration.

Step into [this function](https://github.com/FreeRTOS/coreMQTT/blob/ce8bb2a9761dbdbd77f5dbf31e16c37782446e7f/source/core_mqtt.c#L1683) and see how much data is being received?
