MbedTLS Handshake in Xbee3 with AWS gives Socket closed unexpectedly error after parsing server hello

Hi,
I am working with MCU based solution where i have added extended socket apis in AWS freeRTOS using https://github.com/digidotcom/xbee_ansic_library.
In this implementations i am able to connect to the AWS server using socket create and connect option.
I am using firmware version 11415.

I have written xbee_recv call back such as it uses 8K buffer and this will be filled up with Xbee RF hardware event and can be used for mqtt to to take data from this same buffer.
To do this i have maintained one buffer with two pointers i.e hardware pointer and software pointer.

Hw pointer deals with incoming data from Xbee RF and SW pointer will be used in taking out the data and pas to upper layer.

Now in TLS handshaking phase i am able to achieve “client state: 0” viz. send client hello and “client state: 2” viz. parse server hello, but when it goes to the 3rd state “client state: 3” it goes to mbedtsl_ssl_flush_output it send 167 bytes for flushing ,
but at this point i am receiving socket state “0x76 -Socket closed unexpectedly” and connection lost logs.

Before this stage i received response from AWS for 5350 bytes which i stored in 8K buffer and and nb_want variable got satisfied.

below are my mbedtls enabled logs with MBEDTLS_DEBUG_C macro

mbedTLS: |2| 0x200044cc: client state: 3
mbedTLS: |2| 0x200044cc: => flush output
mbedTLS: |2| 0x200044cc: message length: 159, out_left: 159
Here socket gets closed unexpedtly at sending above bytes

Please help me understand what is going on,

Any help would be greatly appreciable.

Thanks