espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.63k stars 7.28k forks source link

Websocket (with ssl) sending and receiving data restarts (IDFGH-8389) #9858

Closed lyh20190329 closed 2 years ago

lyh20190329 commented 2 years ago

Answers checklist.

IDF version.

v5.0-beta1-473-geea8629fa1

Operating System used.

Linux

How did you build your project?

Command line with CMake

If you are using Windows, please specify command line type.

CMD

Development Kit.

esp32c2

Power Supply used.

External 3.3V

What is the expected behavior?

Call the esp_websocket_client interface to establish a websocket connection, and data can be sent and received normally.

What is the actual behavior?

Call the esp_websocket_client interface to establish a websocket connection, and restart after sending and receiving data for a period of time

Steps to reproduce.

  1. Step:

  2. static void websocket_app_start(void *unused) {

    BaseType_t ret = xTaskCreate(rev_set_msg_task, "rev_set_msg_task", 3 * 1024, NULL, configMAX_PRIORITIES - 1, NULL);
    if (ret != pdPASS)
    {
        ESP_LOGE("==================", "xTaskCreate rev_set_msg_task error==================");
    }
    eques_mac = "test"

    } esp_websocket_client_config_t websocket_cfg = {}; websocket_cfg.uri = ws_url; websocket_cfg.pingpong_timeout_sec = 10; websocket_cfg.ping_interval_sec = 30; websocket_cfg.disable_auto_reconnect = false; websocket_cfg.buffer_size = 2048; websocket_cfg.network_timeout_ms=6000;///ms websocket_cfg.reconnect_timeout_ms=6000;////ms websocket_cfg.keep_alive_enable = true; websocket_cfg.keep_alive_idle=3;///ms websocket_cfg.keep_alive_interval=3;///ms

    client = esp_websocket_client_init(&websocket_cfg);

    esp_websocket_register_events(client, WEBSOCKET_EVENT_ANY, websocket_event_handler, (void *)client); esp_websocket_client_start(client); vTaskDelete(NULL); }

  3. 
    static void websocket_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
    {
    esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data;
    switch (event_id)
    {
    case WEBSOCKET_EVENT_CONNECTED:
        esp_websocket_client_send_text(client, "helloword", strlen("helloword"), WEB_SOCKET_TIME_OUT);
        break;
    case WEBSOCKET_EVENT_DISCONNECTED:
        ESP_LOGI(TAG, "WEBSOCKET_EVENT_DISCONNECTED");
    
        break;
    case WEBSOCKET_EVENT_DATA:
        if (data->op_code == 0x01)
        {
            char *databuf=NULL;
            ESP_LOGI(TAG, "Received=%.*s", data->data_len, (char *)data->data_ptr);
    
        break;
    case WEBSOCKET_EVENT_ERROR:
        ESP_LOGI(TAG, "WEBSOCKET_EVENT_ERROR");
        break;
    case WEBSOCKET_EVENT_CLOSED:
        ESP_LOGI(TAG, "WEBSOCKET_EVENT_CLOSED");
        break;
    }
    }
  4. Step

  5. Step ...

Debug Logs.

Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

Stack dump detected
Core  0 register dump:
MEPC    : 0x4204b5d0  RA      : 0x4204b8f4  SP      : 0x3fcbf3f0  GP      : 0x3fcb0490  
0x4204b5d0: tcp_slowtmr at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/core/tcp.c:1334

0x4204b8f4: tcp_tmr at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/core/tcp.c:244

TP      : 0x3fc913d0  T0      : 0x400586f0  T1      : 0xffffffe0  T2      : 0x00000060  
S0/FP   : 0x3fcc8cf8  S1      : 0x00000000  A0      : 0x00000000  A1      : 0x3fcbe2d0  
A2      : 0x01100048  A3      : 0x00000002  A4      : 0x00000004  A5      : 0x00000082  
A6      : 0x00000000  A7      : 0x00000010  S2      : 0x00000008  S3      : 0x00000000  
S4      : 0x00000000  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000  
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x0000000a  T4      : 0x00000000  T5      : 0x0000000a  T6      : 0x7b02a8c0  
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000005  MTVAL   : 0x01100108  
0x40380001: _vector_table at ??:?

MHARTID : 0x00000000  

Backtrace:

0x4204b5d0 in tcp_slowtmr () at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/core/tcp.c:1334
1334              (pcb->keep_idle + TCP_KEEP_DUR(pcb)) / TCP_SLOW_INTERVAL) {
#0  0x4204b5d0 in tcp_slowtmr () at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/core/tcp.c:1334
#1  0x4204b8f4 in tcp_tmr () at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/core/tcp.c:242
#2  0x4204ffa2 in tcpip_tcp_timer (arg=arg@entry=0x0) at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/core/timeouts.c:149
#3  0x4205009e in sys_check_timeouts () at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/core/timeouts.c:399
#4  0x420470c2 in tcpip_timeouts_mbox_fetch (mbox=mbox@entry=0x3fcb8060 <tcpip_mbox>, msg=msg@entry=0x3fcbf45c) at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/api/tcpip.c:109
#5  0x42047192 in tcpip_thread (arg=<optimized out>) at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/api/tcpip.c:142
#6  0x4038cb10 in prvTaskExitError () at /home/ubuntu/work/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:133
Backtrace stopped: frame did not save the PC
ELF file SHA256: 2ac71544bf033b2c

More Information.

No response

lyh20190329 commented 2 years ago

sometime crash like this:

Stack dump detected Core 0 register dump: MEPC : 0x4204b066 RA : 0x4204d0a8 SP : 0x3fcbe680 GP : 0x3fcb0490
0x4204b066: tcp_recv_null at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/core/tcp.c:1692

0x4204d0a8: tcp_process at /home/ubuntu/work/esp-idf/components/lwip/lwip/src/core/tcp_in.c:986

TP : 0x3fc90728 T0 : 0x400586f0 T1 : 0xffffffe0 T2 : 0xb9e9923d
S0/FP : 0x00007970 S1 : 0x3fcc9134 A0 : 0xffffff53 A1 : 0xffffff53
A2 : 0x00007970 A3 : 0x458a9dc1 A4 : 0x458a9e6e A5 : 0xfbce4630
A6 : 0x00000008 A7 : 0x00000010 S2 : 0x3fccdbee S3 : 0x3fcbf6f4
S4 : 0x00000000 S5 : 0x00000014 S6 : 0x00000000 S7 : 0x00000000
S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
T3 : 0x0000000a T4 : 0x00000000 T5 : 0x0000000a T6 : 0x7b02a8

lyh20190329 commented 2 years ago

The attachment is the websocket interface I used esp_websocket_client.zip