Skip to content

extmod/modlwip: Return EAGAIN from a non-blocking send on ERR_MEM. - #19708

Open
devtejasx wants to merge 1 commit into
micropython:masterfrom
devtejasx:modlwip-nonblocking-send-enomem
Open

devtejasx wants to merge 1 commit into
micropython:masterfrom
devtejasx:modlwip-nonblocking-send-enomem

Conversation

@devtejasx

Copy link
Copy Markdown
Contributor

tcp_sndbuf counts bytes, so it can report room while the segment or heap pool is exhausted and tcp_write returns ERR_MEM. lwip_tcp_send then waited in its retry loop for up to 10 seconds even for a non-blocking socket, stalling a single-threaded event loop.

Nothing is queued on ERR_MEM, so a non-blocking socket can return EAGAIN there, as it already does when tcp_sndbuf is 0. Blocking sockets are unchanged.

Fixes issue #19704.

Summary

Testing

Trade-offs and Alternatives

Generative AI

I did not use generative AI tools when creating this PR.

I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Code size report:

Reference:  esp32/boards/SEEED_XIAO_ESP32C5: Use 0x2000 as the flash offset. [b0310f5]
Comparison: extmod/modlwip: Return EAGAIN from a non-blocking send on ERR_MEM. [merge of a4cc2b0]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +8 +0.001% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.55%. Comparing base (b0310f5) to head (a4cc2b0).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19708   +/-   ##
=======================================
  Coverage   98.55%   98.55%           
=======================================
  Files         182      182           
  Lines       23335    23335           
  Branches        5        5           
=======================================
  Hits        22998    22998           
  Misses        336      336           
  Partials        1        1           
Flag Coverage Δ
unix-coverage-32bit 98.55% <ø> (ø)
unix-coverage-64bit 98.52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

tcp_sndbuf counts bytes, so it can report room while the segment or heap
pool is exhausted and tcp_write returns ERR_MEM.  lwip_tcp_send then waited
in its retry loop for up to 10 seconds even for a non-blocking socket,
stalling a single-threaded event loop.

Nothing is queued on ERR_MEM, so a non-blocking socket can return EAGAIN
there, as it already does when tcp_sndbuf is 0.  Blocking sockets are
unchanged.

Fixes issue micropython#19704.

Signed-off-by: Tejas Nagmote <[email protected]>
@devtejasx
devtejasx force-pushed the modlwip-nonblocking-send-enomem branch from 55f8e62 to a4cc2b0 Compare September 18, 2026 14:17
@dpgeorge

Copy link
Copy Markdown
Member

See #19705.

@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extmod Relates to extmod/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants