# lwIP: pbuf_alloc failed: PBUF_POOL exhausted, total=16, free=0, low=0

- **ID:** `embedded/lwip-pbuf-pool-exhaustion`
- **Domain:** embedded
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

The lwIP PBUF_POOL memory pool is empty because all buffers are in use, typically due to network traffic spikes, memory leaks from unprocessed packets, or insufficient pool size configuration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| lwIP 2.1.3 | active | — | — |
| lwIP 2.2.0 | active | — | — |
| STM32Cube_FW_H7_V1.11.0 | active | — | — |

## Workarounds

1. **Increase PBUF_POOL_SIZE in lwipopts.h (e.g., from 16 to 32 or 64) to handle burst traffic, and reduce PBUF_POOL_BUFSIZE if packet sizes are small.** (85% success)
   ```
   Increase PBUF_POOL_SIZE in lwipopts.h (e.g., from 16 to 32 or 64) to handle burst traffic, and reduce PBUF_POOL_BUFSIZE if packet sizes are small.
   ```
2. **Add a check in the Ethernet ISR to drop packets if pool is low, preventing system lockup: `if (pbuf_alloc(PBUF_RAW, 0, PBUF_POOL) == NULL) { return ERR_MEM; }`** (75% success)
   ```
   Add a check in the Ethernet ISR to drop packets if pool is low, preventing system lockup: `if (pbuf_alloc(PBUF_RAW, 0, PBUF_POOL) == NULL) { return ERR_MEM; }`
   ```
3. **Implement a periodic task to free orphaned pbufs by checking `lwip_stats.mem.used` and calling `tcpip_thread()` processing to flush queues.** (80% success)
   ```
   Implement a periodic task to free orphaned pbufs by checking `lwip_stats.mem.used` and calling `tcpip_thread()` processing to flush queues.
   ```

## Dead Ends

- **** — Larger windows require more buffers; if the pool size isn't increased, exhaustion still occurs under load. (80% fail)
- **** — This shifts computation to CPU but doesn't affect buffer allocation; pool exhaustion persists. (90% fail)
- **** — ARP cache management doesn't free PBUF_POOL buffers; those are for packet data, not ARP entries. (95% fail)
