LWIP assertion triggers after +10 hours

nicolasmm
Posts: 6
Joined: Thu Sep 05, 2019 5:20 pm

LWIP assertion triggers after +10 hours

Postby nicolasmm » Tue Dec 17, 2019 2:34 pm

I have a UDP server, receiving a stream a calculating the jitter to send a package back after 50 packets received.
My application must run indefinitely, but after more than 3 hours the following assertion gests triggered.

assertion "pbuf_free: p->ref > 0" failed: file "/home/user/esp/esp-idf/components/lwip/lwip/src/core/pbuf.c", line 757, function: pbuf_free
abort() was called at PC 0x4016d06b on core 0
0x4016d06b: __assert_func at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdlib/assert.c:62 (discriminator 8)


ELF file SHA256: e8aca13bf40ee60f6921fe1cd7ee8f2fb5c34c654f2ed21fd7527937fa2bcde3

Backtrace: 0x40094995:0x3ffcbca0 0x40094d85:0x3ffcbcc0 0x4016d06b:0x3ffcbce0 0x40091dee:0x3ffcbd10 0x4009173e:0x3ffcbd30 0x4009277f:0x3ffcbd50 0x400dc77b:0x3ffcbdb0 0x4009824d:0x3ffcc780
0x40094995: invoke_abort at /home/user/esp/esp-idf/components/esp32/panic.c:157

0x40094d85: abort at /home/user/esp/esp-idf/components/esp32/panic.c:174

0x4016d06b: __assert_func at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdlib/assert.c:62 (discriminator 8)

0x40091dee: pbuf_free at /home/user/esp/esp-idf/components/lwip/lwip/src/core/pbuf.c:757 (discriminator 1)

0x4009173e: netbuf_free at /home/user/esp/esp-idf/components/lwip/lwip/src/api/netbuf.c:131

0x4009277f: lwip_sendto at /home/user/esp/esp-idf/components/lwip/lwip/src/api/sockets.c:1678

0x400dc77b: sendto at /home/user/esp/esp-idf/components/lwip/lwip/src/include/lwip/sockets.h:654
(inlined by) tUDPserver(void*) at /home/user/esp/UDP/build/../main/main.cpp:766

0x4009824d: vPortTaskWrapper at /home/user/esp/esp-idf/components/freertos/port.c:143

Code: Select all

void tUDPserver(void *pvParameters)
{
    struct sockaddr_in udpAddr;
    udpAddr.sin_addr.s_addr = htonl(INADDR_ANY); 
    udpAddr.sin_family = AF_INET; 
    udpAddr.sin_port = htons(cam->client_rtp_port);

    int sock_udp;

    source stream;
    rtcp_rr_t rr;
    uint8_t cont_pqtes = 0;

    uint8_t rx_data[2048] = {0};
    int32_t rx_size = 0;


    while (1) {

        if (sock_udp < 0)
        {
            sock_udp = socket(udpAddr.sin_family, SOCK_DGRAM, IPPROTO_IP);
            if (sock_udp < 0) {
                ESP_LOGE(tag, "Unable to create socket RTP_server:  %d : %s", errno, strerror(errno));
                close_socket(&sock_udp);
                continue;
            }
            ESP_LOGI(tag, "Socket created");

            
            int err = bind(cam->sock_udp, (struct sockaddr *)&udpAddr, sizeof(udpAddr));
            if (err < 0) {
                ESP_LOGE(tag, "Socket unable to bind", errno, strerror(errno));
                close_socket(&cam->sock_udp);
                continue;
            }
        } else ESP_LOGW (tag, "Socket is open");

        
        while (1) 
        {
            struct sockaddr_in6 source_addr; // Large enough for both IPv4 or IPv6
            socklen_t socklen = sizeof(source_addr);
            rx_size = recvfrom(cam->sock_udp, rx_data, sizeof(rx_data) - 1, 0, (struct sockaddr *)&source_addr, &socklen);

            // Error occured during receiving
            if (rx_size < 0) {
                ESP_LOGE(tag, "recvfrom udp failed:  %d : %s", errno, strerror(errno));
                break;
            }
            else {

                cal_jitter(&stream, &rr, &rtp_hdr, esp_timer_get_time()/1000);
                cont_pqtes ++;
                

                // Send reciever report
                if (cont_pqtes >= 50){
                    rr.ssrc = rtp_hdr.ssrc;
                    uint8_t buff_report [32];
                    uint8_t len_buf = reciever_report(&stream, &rr, buff_report, sizeof(buff_report));
                    cont_pqtes = 0;
                    // Send data 
                    int err = sendto(cam->sock_udp, buff_report, len_buf, 0, (struct sockaddr *)&source_addr, sizeof(source_addr));
                    if (err < 0) {
                        ESP_LOGE(tag, "Error Sending ReceiverRepor failed:  %d : %s", errno, strerror(errno));
                    }
                }
            }
        }
    }
    vTaskDelete(NULL);
}

ESP_Angus
Posts: 2072
Joined: Sun May 08, 2016 4:11 am

Re: LWIP assertion triggers after +10 hours

Postby ESP_Angus » Tue Dec 17, 2019 10:29 pm

Hi nicolas,

Thanks for this report. I have a couple of follow up questions:

What version of ESP-IDF are you using? You can get this by changing to the IDF_PATH directory and running "git describe --tags --dirty".

Also, can you tell us anything else about your project: What else is running at the same time as this loop? Have you changed any default LWIP settings? Are you using PSRAM?

Thanks,

Angus

nicolasmm
Posts: 6
Joined: Thu Sep 05, 2019 5:20 pm

Re: LWIP assertion triggers after +10 hours

Postby nicolasmm » Wed Dec 18, 2019 4:10 pm

Hi,

Yes, I'm using PSRAM. Below is the return to the git command.

Code: Select all

git describe --tags --dirty
v4.1-dev-371-ga3af95085-dirty
And this are the Configurations:

Code: Select all

CONFIG_LWIP_L2_TO_L3_COPY=y
CONFIG_LWIP_IRAM_OPTIMIZATION=y
CONFIG_LWIP_TIMERS_ONDEMAND=y
CONFIG_LWIP_MAX_SOCKETS=1
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
# CONFIG_LWIP_SO_RCVBUF is not set
# CONFIG_LWIP_NETBUF_RECVINFO is not set
# CONFIG_LWIP_IP_FRAG is not set
# CONFIG_LWIP_IP_REASSEMBLY is not set
# CONFIG_LWIP_STATS is not set
# CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
# CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set
# CONFIG_LWIP_TCP_OVERSIZE_DISABLE is not set
# CONFIG_LWIP_WND_SCALE is not set
At the same time of the loop, I am running:
- SDCard task [10K stack size].
- i2c slave reading and writing task [4K stack size].
- NTP server task [3K stack size].
- WebSocket client task [10K stack size].

Who is online

Users browsing this forum: No registered users and 20 guests