RT-Thread / RT-Thread/rt-thread
[Bug] netstat
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 12.2k
- Forks
- 5.4k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 40
Description
RT-Thread Version
5.2.1
Hardware Type/Architectures
STM32H743
Develop Toolchain
GCC
Describe the bug
在 rt-thread/components/net/lwip/port/ethernetif.c 中
list_if, list_tcps, list_udps 函数调用 rt_kprintf 之前由于调用了 rt_enter_critical(); 导致调度器上锁,在 rt_kprintf 中调用 console 设备时,使用 rt_mutex_t 导致在调度器上锁时出现死锁。
详细的调用堆栈如下:
void list_if(void)
{
......
rt_enter_critical();
......
while( netif != RT_NULL )
{
rt_kprintf("network interface: %c%c%s\n",
netif->name[0],
netif->name[1],
(netif == netif_default)?" (Default)":"");
...
}
....
}
rt_weak int rt_kprintf(const char *fmt, ...)
{
...
_kputs(rt_log_buf, length);
...
}
static void _kputs(const char *str, long len)
{
.....
rt_device_write(console_device, 0, str, len);
....
}
static rt_ssize_t telnet_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
{
......
rt_mutex_take(telnet->tx_ringbuffer_lock, RT_WAITING_FOREVER);
......
}
static rt_err_t _rt_mutex_take(rt_mutex_t mutex, rt_int32_t timeout, int suspend_flag)
{
struct rt_thread *thread;
rt_err_t ret;
/* this function must not be used in interrupt even if time = 0 */
/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
...
}
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \
do \
{ \
if (need_check) \
{ \
if (rt_critical_level() != 0) \
{ \
rt_kprintf("Function[%s]: scheduler is not available\n", \
__FUNCTION__); \
RT_ASSERT(0) \
} \
RT_DEBUG_IN_THREAD_CONTEXT; \
} \
}
然后将会再次调用 rt_kprintf,一直重复,直到堆栈溢出。
Other additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in rt-thread/components/net/lwip/port/ethernetif.c with list_if, list_tcps, and list_udps, then trace rt_kprintf through _kputs to telnet_write and _rt_mutex_take. Reproduce the scheduler-locking path on the reported STM32H743/GCC setup and confirm that diagnostic output no longer recurses or deadlocks while the netstat commands still report their data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- networking, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100