Skip to content

gh-109015: Add test.support.socket_helper.tcp_blackhole() - #109016

Merged
vstinner merged 3 commits into
python:mainfrom
vstinner:tcp_blackhole
Sep 6, 2023
Merged

vstinner merged 3 commits into
python:mainfrom
vstinner:tcp_blackhole

Conversation

@vstinner

@vstinner vstinner commented Sep 6, 2023 •

Copy link
Copy Markdown
Member
@vstinner

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member Author

My previous DEBUG PR: PR #108972.

See also issue #91960 "Add FreeBSD build and test using Cirrus-CI" and PR #91961 which the TCP blackhole was discussed.

@vstinner

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member Author

I validated my fix on Cirrus-CI with this patch:

diff --git a/.cirrus.yml b/.cirrus.yml
index 823b1f921d66d..2e087f1f57706 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -7,9 +7,9 @@ freebsd_task:
   # local local connections to fail with ETIMEDOUT instead of ECONNREFUSED.
   # For more information see https://reviews.freebsd.org/D41751 and
   # https://github.com/cirruslabs/cirrus-ci-docs/issues/483.
-  sysctl_script:
-    - sysctl net.inet.tcp.blackhole=0
-    - sysctl net.inet.udp.blackhole=0
+#  sysctl_script:
+#    - sysctl net.inet.tcp.blackhole=0
+#    - sysctl net.inet.udp.blackhole=0
   build_script:
     - mkdir build
     - cd build

test_asyncio failed at the first version of my PR, which proves that the Cirrus-CI did its job: test my fix :-) I had to skip 2 more tests in test_asyncio.

At the second version, it passed: Total test files: run=461/461 skipped=25 resource_denied=1 rerun=1: https://cirrus-ci.com/task/4512145228955648 (test.test_asyncio.test_subprocess had to be re-run, it's unrelated to this fix.)

cc @emaste

@vstinner

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member Author

My second patch adds skips to Lib/test/test_asyncio/test_events.py:

  • test_create_connection_local_addr_skip_different_family()
  • test_create_connection_local_addr_nomatch_family()
@vstinner

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member Author

I reverted the Cirrus CI change.

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).
Comment thread Lib/test/support/socket_helper.py Outdated
except KeyError:
pass

cmd = ['sysctl', name]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sysctl provides a -n arg to suppress the name:

$ sysctl -n net.inet.tcp.blackhole
0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I didn't know it. It's also supported by Linux (even if right now, this function is only called on FreeBSD ;-)). I updated my PR.

@gvanrossum
gvanrossum removed their request for review September 6, 2023 19:23
@vstinner

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member Author

I ran a quick test on my latest PR:

vstinner@freebsd$ sudo sysctl net.inet.tcp.blackhole=0
net.inet.tcp.blackhole: 0 -> 0
vstinner@freebsd$ ./python -m test -v test_socket -m test_connect -v
(...)
test_connect (test.test_socket.NetworkConnectionNoServer.test_connect) ... ok
(...)
Result: SUCCESS

and:

vstinner@freebsd$ sudo sysctl net.inet.tcp.blackhole=2
net.inet.tcp.blackhole: 0 -> 2

vstinner@freebsd$ ./python -m test -v test_socket -m test_connect -v
(...)
test_connect (test.test_socket.NetworkConnectionNoServer.test_connect) ... skipped 'TCP blackhole is enabled (sysctl 
(...)
Result: SUCCESS
@vstinner

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member Author

@emaste: Would you mind to review the updated PR?

Comment thread Lib/test/support/socket_helper.py Outdated
return None
output = proc.stdout

# Parse 'net.inet.tcp.blackhole: 0\n' to get '0'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is leftover

@vstinner
vstinner enabled auto-merge (squash) September 6, 2023 23:28
@vstinner vstinner added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Sep 6, 2023
@vstinner
vstinner disabled auto-merge September 6, 2023 23:57
@vstinner
vstinner merged commit a52a350 into python:main Sep 6, 2023
@vstinner
vstinner deleted the tcp_blackhole branch September 6, 2023 23:58
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @vstinner, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker a52a3509770f29f940cda9307704908949912276 3.11

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 6, 2023
…onGH-109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).
(cherry picked from commit a52a350)

Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-bot

Copy link
Copy Markdown

GH-109041 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Sep 6, 2023
vstinner added a commit to vstinner/cpython that referenced this pull request Sep 7, 2023
…on#109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).

(cherry picked from commit a52a350)
@bedevere-bot

Copy link
Copy Markdown

GH-109042 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Sep 7, 2023
vstinner added a commit that referenced this pull request Sep 7, 2023
…9016) (#109042)

gh-109015: Add test.support.socket_helper.tcp_blackhole() (#109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).

(cherry picked from commit a52a350)
Yhg1s pushed a commit that referenced this pull request Sep 8, 2023
…109016) (#109041)

gh-109015: Add test.support.socket_helper.tcp_blackhole() (GH-109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).
(cherry picked from commit a52a350)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants