SSL crash

zaxl
Posts: 29
Joined: Mon Jun 08, 2015 6:34 pm
Contact:

SSL crash

Postby zaxl » Tue Jul 07, 2015 11:16 pm

Hi,

If i call espconn_secure_disconnect() from receive_callback() the SDK randomly crashes crashes - tried with both 1.1.2 and 1.2 .

I'm using - https://github.com/zazolabs/esphttpclient.git
Regards,
zaxl

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: SSL crash

Postby ESP_Faye » Wed Jul 08, 2015 11:23 am

Hi,

Sorry for the inconvenience.

Please don’t call espconn_disconnect (or espconn_secure_disconnect) to break the TCP connection in any espconn callback.
If it is needed, please use system_os_task and system_os_post to trigger the disconnection ( espconn_disconnect or espconn_secure_disconnect).

zaxl
Posts: 29
Joined: Mon Jun 08, 2015 6:34 pm
Contact:

Re: SSL crash

Postby zaxl » Wed Jul 08, 2015 3:00 pm

Hi,

thanks for the fast replay!

But if i use an os task to close the connection there is a race condition:

recv callback:
system_os_post (..., close_connection, conn)
disconnected cb:
free connection

close_connection_os_task:
conn -> now points to a freed memory crash again



Is there a warranty that the os task will run before any other callbacks? Same goes for the case when using some context structure instead of directly using espconn.
Regards,
zaxl

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: SSL crash

Postby ESP_Faye » Thu Jul 09, 2015 3:44 pm

Hi,

Please refer to SSL demo here http://bbs.espressif.com/viewtopic.php?f=21&t=389

Add code below to disconnect

Code: Select all

os_event_t *testQueue;
#define TEST_QUEUE_LEN 4

void test_task(os_event_t *e){
    os_printf("test_task !!! \r\n");
    espconn_secure_disconnect(&user_tcp_conn);
}

LOCAL void ICACHE_FLASH_ATTR
user_tcp_recv_cb(void *arg, char *pusrdata, unsigned short length)
{
   //received some data from tcp connection
   
    os_printf("tcp recv !!! %s \r\n", pusrdata);
   
   testQueue = (os_event_t*) os_malloc(sizeof(os_event_t) * TEST_QUEUE_LEN);
   system_os_task(test_task, 0, testQueue, TEST_QUEUE_LEN);
   system_os_post(0, 0, 0);

}


More details about "system_os_task" and "system_os_post" please refer to documentation "2C-ESP8266__SDK__Programming Guide"

Thanks for your interest in Espressif Systems and ESP8266 !

zaxl
Posts: 29
Joined: Mon Jun 08, 2015 6:34 pm
Contact:

Re: SSL crash

Postby zaxl » Thu Jul 09, 2015 7:58 pm

Hi,

The problem is a bit different.
You have a client and a server, T is time T+X relative time.

Client: Server:
T+0
user_tcp_recv_cb(...)
{
does os post task
}

T+1: closes the connection
T+2:
app receives disconnected callback and frees the connection.

T+3:
Now the SDK runs the posted task from the tcp_recv_cb
and tries to disconnect the connection again. -> BOOM



I've got it working but i'm not sure it is not 'just working'.

Thanks one more time!
Regards,
zaxl

Who is online

Users browsing this forum: No registered users and 30 guests