Skip to content

tests/extmod: Close UDP timely. #17660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025
Merged

Conversation

yf13
Copy link
Contributor

@yf13 yf13 commented Jul 11, 2025

Summary

This adds call to release UDP port timely so that to reuse it in other tests. Otherwise, one could face issue like https://github.com/orgs/micropython/discussions/17623.

Testing

Tested with VARIANT coverage of UNIX port on Ubuntu 22.04.

Copy link

codecov bot commented Jul 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.44%. Comparing base (8f8f853) to head (2743068).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17660   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files         171      171           
  Lines       22192    22192           
=======================================
  Hits        21847    21847           
  Misses        345      345           

☔ View full report in Codecov by Sentry.
📢 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.

@yf13 yf13 force-pushed the pull-udp-close branch from d418563 to a2d267a Compare July 11, 2025 00:36
@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Jul 11, 2025
@dpgeorge
Copy link
Member

Thanks for the contribution. This is a good fix.

But I think the socket also needs to be closed in the initial detection part of the script at the top.

This bit of code:

try:
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(socket.getaddrinfo("127.0.0.1", 8000)[0][-1])
except OSError:
    print("SKIP")
    raise SystemExit

should probably be changed to:

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
    s.bind(socket.getaddrinfo("127.0.0.1", 8000)[0][-1])
except OSError:
    s.close()
    print("SKIP")
    raise SystemExit

@yf13
Copy link
Contributor Author

yf13 commented Jul 11, 2025

@dpgeorge thanks for the comment. But I have some concerns regarding this close-before-SKIP:

  • This close() before SKIP doesn't help to free the UDP port earlier, right?
  • The unbound socket will be closed (e.g. by GC) later, so not closing it here may help to reveal more issues?
  • The scope of changes will grow as same pattern appear in more places (e.g. select_ipoll.py etc).

So do we really want that?

@dpgeorge
Copy link
Member

  • This close() before SKIP doesn't help to free the UDP port earlier, right?

Correct. The s.close() still needs to be added at the end of the test, as done in this PR.

  • The unbound socket will be closed (e.g. by GC) later, so not closing it here may help to reveal more issues?

Correct, it will eventually be closed by the GC (most likely on soft reset).

Usually we like to make the tests clean up properly after themselves. You are right that it may help reveal more issues, although there should be other tests for that.

  • The scope of changes will grow as same pattern appear in more places

Yes there are a few other tests where this pattern appears, and would need to be fixed for consistency.

If you want to keep this PR small and of limited scope, then I'm happy for it to stay as-is, just closing the socket at the end of the test. At least that helps with the situation you identified, running the tests in parallel.

@yf13
Copy link
Contributor Author

yf13 commented Jul 13, 2025

@dpgeorge, thank you for the confirmations. as I am too new to the code base, it is better to stick with small changes fow now. We can do more cleanups later in separate PR, how do you think?

@dpgeorge
Copy link
Member

We can do more cleanups later in separate PR, how do you think?

Yes, I'm always happy to have smaller changes.

This adds call to release UDP port in a timely manner, so they can be
reused in subsequent tests.  Otherwise, one could face issue like micropython#17623.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
@dpgeorge dpgeorge merged commit 2743068 into micropython:master Jul 15, 2025
27 checks passed
@yf13 yf13 deleted the pull-udp-close branch July 16, 2025 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Relates to tests/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy