Hello.
I use MBEDTLS with LwIP and FreeRTOS. Project generated in CubeMX, STM32 microcontroller.
I also took as a basis the examples provided by ST, and also looked at the ssl-client2.c file, which is in the repository on Github.
My mode of operation is:
- Connect to server
- I start the handshake process
- I make a GET request to the server
- I get an answer
- Disconnect from the server, calling its function Reconnect:
uint8_t Reconnect(void)
{
uint32_t tickstart = 0;
do {
error_dbg.ssl_close_notify++;
ret = mbedtls_ssl_close_notify( &ssl );
}while( ret == MBEDTLS_ERR_SSL_WANT_WRITE );
mbedtls_net_free(&server_fd);
tickstart = xTaskGetTickCount();
while((ret = mbedtls_ssl_session_reset(&ssl)) !=0)
{
if((xTaskGetTickCount() - tickstart) > 2500)
{
return 1;
}
}
tickstart = xTaskGetTickCount();
while((ret = mbedtls_ssl_set_session( &ssl, &saved_session )) != 0)
{
if((xTaskGetTickCount() - tickstart) > 2500)
{
return 2;
}
}
return 0;
}
Next, go to step 1 and the whole process repeats.
But there is a problem - after a while (30-60 minutes, and sometimes more) I see an error in the debugger: the handshake process ends with an error or time-out and I need to reset the microcontroller in order to restore the data exchange with the server.
I tried cleaning up all the SSL — like in the ssl-client2.c file, when going to the exit label. Then I re-initialize SSL and start the exchange with the server. This helps, but I noticed that after that an error in the handshake occurs very often - once every 5-7 attempts. But if you reset the microcontroller, then the first few tens of minutes of errors do not occur.
Do I close the connection to the server correctly? And how to make a complete cleaning of SSL, so that the exchange with the server happens without errors?