examples/device/net_lwip_webserver/src/main.c random crashes and hangs

Open
#3,276 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c
Domain
embedded-iot

Research direction

Start with examples/device/net_lwip_webserver/src/main.c and inspect linkoutput_fn, then trace how tud_task() and the lwIP output callback interact in this example. Check the example's existing network tests or build instructions, if present. Done means transmission no longer calls lwIP recursively, and the failure return code follows lwIP's expected behavior.

Written by the indexing model from the issue text.

Description

tinyusb

In this function:

static err_t linkoutput_fn(struct netif *netif, struct pbuf *p) {
  (void) netif;

  for (;;) {
    /* if TinyUSB isn't ready, we must signal back to lwip that there is nothing we can do */
    if (!tud_ready())
      return ERR_USE;

    /* if the network driver can accept another packet, we make it happen */
    if (tud_network_can_xmit(p->tot_len)) {
      tud_network_xmit(p, 0 /* unused for this example */);
      return ERR_OK;
    }

    /* transfer execution to TinyUSB in the hopes that it will finish transmitting the prior packet */
    tud_task(); **/* <= this may call lwip recursively, which isn't allowed by lwip and can cause data corruption of lwip data */**
  }
}

"tud_task()" might call prohibited functions of the lwip stack recursively and will cause random hangs, crashes and data corruption.
Why is it a loop?
Also if this function fails, it is supposed to return ERR_MEM, not ERR_USE.

Is this an error not noticed yet?

Dominant language
C
Stars
5k
Forks
1.3k
Avg merge
12d 19h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/pico-sdk

All issues in raspberrypi/pico-sdk

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.