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

Add keepalive_timeout parameter to web.run_app #5095

Merged
merged 16 commits into from
Oct 27, 2020
Merged

Conversation

janbuchar
Copy link
Contributor

@janbuchar janbuchar commented Oct 20, 2020

What do these changes do?

Add keepalive_timeout parameter to web.run_app. Closes #5094.

Are there changes in behavior for the user?

Unlikely.

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_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 20, 2020
@janbuchar janbuchar marked this pull request as ready for review October 20, 2020 11:25
@codecov-io
Copy link

codecov-io commented Oct 20, 2020

Codecov Report

Merging #5095 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5095      +/-   ##
==========================================
+ Coverage   97.63%   97.64%   +0.01%     
==========================================
  Files          43       43              
  Lines        8999     8999              
  Branches     1413     1413              
==========================================
+ Hits         8786     8787       +1     
+ Misses         99       98       -1     
  Partials      114      114              
Flag Coverage Δ
#unit 97.64% <ø> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
aiohttp/web.py 99.52% <ø> (ø)
aiohttp/web_fileresponse.py 98.38% <0.00%> (+0.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a8bf3a...fcc6de6. Read the comment docs.

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

See the initial review from me below. It's non-blocking but I don't have the confidence to accept this change on my own either and thus I defer the decision on whether it's something that we want to @asvetlov.

@@ -685,6 +686,24 @@ async def on_startup(app):
exc_handler.assert_called_with(patched_loop, msg)


def test_run_app_keepalive_timeout(patched_loop):
Copy link
Member

Choose a reason for hiding this comment

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

It's usually better to use the mocker fixture from pytest-mock (it's already integrated as a test dependency) for accessing the MagicMock class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can update it. What exactly is the benefit of using the fixture?

Copy link
Member

Choose a reason for hiding this comment

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

Just the consistency: if the lib is integrated, the expectation is that it would be used. Also, pytest design is more fixture-driven so external things seem foreign.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. I can change this (and the rest of the comments) if @asvetlov agrees with the feature itself.

base_runner_init_mock(*args, **kwargs)
base_runner_init_orig(self, *args, **kwargs)

with mock.patch.object(BaseRunner, "__init__", base_runner_init_spy):
Copy link
Member

Choose a reason for hiding this comment

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

It's better to use the built-in monkeypatch fixture for patching things.
Also, it's best to only patch the line that relies on patching, not many lines because you may accidentally create unintended side-effects with this.

tests/test_run_app.py Show resolved Hide resolved
tests/test_run_app.py Outdated Show resolved Hide resolved
base_runner_init_orig = BaseRunner.__init__

def base_runner_init_spy(self, *args, **kwargs):
base_runner_init_mock(*args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like it'd be much cleaner to just do

Suggested change
base_runner_init_mock(*args, **kwargs)
assert kwargs["keepalive_timeout"] == new_timeout

docs/web_reference.rst Show resolved Hide resolved
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
@asvetlov
Copy link
Member

@webknjaz please feel free to merge the PR when you are okay with it.

@janbuchar janbuchar requested a review from webknjaz October 26, 2020 13:56
@@ -2798,6 +2798,8 @@ Utilities
closed after a HTTP request. The delay
allows for reuse of a TCP connection.

.. versionadded:: 3.7
Copy link
Member

@asvetlov asvetlov Oct 26, 2020

Choose a reason for hiding this comment

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

Suggested change
.. versionadded:: 3.7
.. versionadded:: 3.8

Sorry, the time window for 3.1 is closed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood.

@janbuchar
Copy link
Contributor Author

@asvetlov is there any agreed-upon autoformatting tool that could help me resolve the conflicts?

@asvetlov
Copy link
Member

You can try the following:

  1. Copy https://github.com/aio-libs/aiohttp/blob/master/.pre-commit-config.yaml to your local repository.
  2. Install pre-commit: pip install -U pre-commit
  3. Apply all hooks: pre-commit run --all-files Repeat the step several times until all checks are green.
  4. I hope your local copy will be in sync after reformatting; git merge upstream/master should be succeeded. If not -- the only manual conflict resolving can help

@janbuchar janbuchar requested a review from asvetlov October 27, 2020 18:42
tests/test_run_app.py Outdated Show resolved Hide resolved
tests/test_run_app.py Outdated Show resolved Hide resolved
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
@webknjaz webknjaz merged commit 6747ed9 into aio-libs:master Oct 27, 2020
@github-actions
Copy link
Contributor

💔 Backport was not successful

The PR was attempted backported to the following branches:

  • ❌ 3.8: Commit could not be cherrypicked due to conflicts

asvetlov added a commit that referenced this pull request Oct 29, 2020
PR #5095 by @Teyras

Co-authored-by: Sviatoslav Sydorenko <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
@asvetlov
Copy link
Member

@webknjaz please backport manually next time if the bot fails.
Or, at least, let me know that I should do it myself

@webknjaz
Copy link
Member

Oh, I probably missedmisse that among my notifications. I think it's also a good idea to encourage the submitters to do their backports when they are as interested in the change.

@asvetlov
Copy link
Member

asvetlov commented Oct 29, 2020

I think it's also a good idea to encourage the submitters to do their backports when they are as interested in the change.

Agree, ask for the submitter to make backport PR using cherry_picker tool (already installed by requirements/dev.txt) is a good idea.
I think the person who merges a PR should monitor Backport statuses and try to manually backport himself on failure.
It works well pretty often when conflict resolution is trivial.
In a complex case, the merger can kindly ask for manual backporting.

@asvetlov
Copy link
Member

For the note, backported to 3.8 by e88dc8a

commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
PR aio-libs#5095 by @Teyras

Co-authored-by: Sviatoslav Sydorenko <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
PR aio-libs#5095 by @Teyras

Co-authored-by: Sviatoslav Sydorenko <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Allow configuring the keepalive timeout in web.run_app
4 participants