Skip to content
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

Expose setsockopt in TCPConnector API #10474

Merged
merged 4 commits into from
Feb 21, 2025

Conversation

TimMenninger
Copy link
Contributor

@TimMenninger TimMenninger commented Feb 20, 2025

Optionally give tcp_sockopts to the constructor of TCPConnector, which will be a list of tuples of (level, optname, value). Each tuple is deconstructed and passed as arguments to .setsockopt. One such use case for this feature would be to modify the keepalive behavior leading up to considering a connection dead by setting TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT sockopts.

What do these changes do?

These changes allow the caller to pass arguments understood by <socket>.setsockopt to be applied to the socket created in TCPConnector.

Are there changes in behavior for the user?

The changes contained in this PR are opt-in by passing values in tcp_sockopts parameter to the TCPConnector class construction.

Is it a substantial burden for the maintainers to support this?

I sure hope not.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)

    • if you don't have an issue number, change it to the pull request
      number after creating the PR

      • .bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • .feature: A new behavior, public APIs. That sort of stuff.
      • .deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • .breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • .doc: Notable updates to the documentation structure or build
        process.
      • .packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • .contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • .misc: Changes that are hard to assign to any of the above
        categories.
    • Make sure to use full sentences with correct case and punctuation,
      for example:

      Fixed issue with non-ascii contents in doctest text files
      -- by :user:`contributor-gh-handle`.

      Use the past tense or the present tense a non-imperative mood,
      referring to what's changed compared to the last released version
      of this project.

@TimMenninger TimMenninger force-pushed the setsockopts-tcpconnector branch from 22ed317 to 782f720 Compare February 20, 2025 17:07
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Feb 20, 2025
@TimMenninger TimMenninger force-pushed the setsockopts-tcpconnector branch from 401a0aa to 47b9a3f Compare February 20, 2025 17:08
@TimMenninger TimMenninger marked this pull request as ready for review February 20, 2025 17:10
Copy link

codspeed-hq bot commented Feb 20, 2025

CodSpeed Performance Report

Merging #10474 will not alter performance

Comparing TimMenninger:setsockopts-tcpconnector (105f0b8) with master (60819de)

Summary

✅ 47 untouched benchmarks

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.70%. Comparing base (60819de) to head (105f0b8).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10474   +/-   ##
=======================================
  Coverage   98.70%   98.70%           
=======================================
  Files         122      122           
  Lines       37209    37225   +16     
  Branches     2060     2063    +3     
=======================================
+ Hits        36727    36743   +16     
  Misses        335      335           
  Partials      147      147           
Flag Coverage Δ
CI-GHA 98.58% <93.75%> (-0.01%) ⬇️
OS-Linux 98.25% <93.75%> (-0.01%) ⬇️
OS-Windows 96.18% <93.75%> (+<0.01%) ⬆️
OS-macOS 97.36% <93.75%> (-0.01%) ⬇️
Py-3.10.11 97.27% <87.50%> (-0.01%) ⬇️
Py-3.10.16 97.81% <87.50%> (-0.01%) ⬇️
Py-3.11.11 97.90% <87.50%> (+<0.01%) ⬆️
Py-3.11.9 97.36% <87.50%> (+<0.01%) ⬆️
Py-3.12.8 97.14% <87.50%> (-0.01%) ⬇️
Py-3.12.9 98.33% <87.50%> (-0.01%) ⬇️
Py-3.13.1 97.14% <87.50%> (-0.02%) ⬇️
Py-3.13.2 98.32% <87.50%> (-0.02%) ⬇️
Py-3.9.13 97.16% <87.50%> (+<0.01%) ⬆️
Py-3.9.21 97.69% <87.50%> (-0.01%) ⬇️
Py-pypy7.3.16 77.24% <87.50%> (-17.29%) ⬇️
VM-macos 97.36% <93.75%> (-0.01%) ⬇️
VM-ubuntu 98.25% <93.75%> (-0.01%) ⬇️
VM-windows 96.18% <93.75%> (+<0.01%) ⬆️

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

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

@TimMenninger TimMenninger force-pushed the setsockopts-tcpconnector branch 2 times, most recently from 12cc977 to ff8f623 Compare February 20, 2025 17:58
@TimMenninger TimMenninger marked this pull request as draft February 20, 2025 17:58
@TimMenninger TimMenninger force-pushed the setsockopts-tcpconnector branch 4 times, most recently from b6d7b93 to 3a0fb1c Compare February 20, 2025 18:39
@TimMenninger TimMenninger marked this pull request as ready for review February 20, 2025 18:52
@bdraco
Copy link
Member

bdraco commented Feb 20, 2025

It looks like there is a conflict now.

Would you please update the PR description to better explain the use case and motivation for this change.

Copy link
Member

@Dreamsorcerer Dreamsorcerer left a comment

Choose a reason for hiding this comment

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

Seems like a reasonable addition to me, if there's good usecases for it.

@bdraco bdraco added the backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot label Feb 20, 2025
@TimMenninger TimMenninger force-pushed the setsockopts-tcpconnector branch from c8357a0 to 807b21b Compare February 21, 2025 15:21
@TimMenninger TimMenninger force-pushed the setsockopts-tcpconnector branch from 807b21b to ffd308b Compare February 21, 2025 15:25
@TimMenninger
Copy link
Contributor Author

It looks like there is a conflict now.

Would you please update the PR description to better explain the use case and motivation for this change.

Updated with a sample use case taken directly from my own motivation for this change.

@TimMenninger TimMenninger force-pushed the setsockopts-tcpconnector branch from ffd308b to 8aef1f1 Compare February 21, 2025 16:30
Optionally give tcp_sockopts to the constructor of TCPConnector, which
will be a list of tuples of (level, optname, value). Each tuple is
deconstructed and passed as arguments to <socket>.setsockopt.
@TimMenninger TimMenninger force-pushed the setsockopts-tcpconnector branch from 8aef1f1 to 1a20f7e Compare February 21, 2025 16:40
@Dreamsorcerer Dreamsorcerer merged commit 7379a86 into aio-libs:master Feb 21, 2025
40 checks passed
Copy link
Contributor

patchback bot commented Feb 21, 2025

Backport to 3.12: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.12/7379a866bb9fa41986a01aa6fff2a73a210b66de/pr-10474

Backported as #10486

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Feb 21, 2025
Dreamsorcerer pushed a commit that referenced this pull request Feb 21, 2025
… API (#10486)

**This is a backport of PR #10474 as merged into master
(7379a86).**

Co-authored-by: Tim Menninger <tmenninger22@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants