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

Allow configuring max_incomplete_event_size for h11 implementation #1240

Closed
wants to merge 4 commits into from

Conversation

alexiri
Copy link

@alexiri alexiri commented Nov 7, 2021

Solves #1234.

uvicorn/main.py Outdated Show resolved Hide resolved
@alexiri alexiri requested a review from Kludex November 7, 2021 21:11
Copy link
Author

@alexiri alexiri left a comment

Choose a reason for hiding this comment

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

Changes implemented in ee25dfc. @Kludex could you please take a look?

Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

We probably want to add a test on the test_http.py for h11, using the new h11_max_incomplete_event_size.

@alexiri
Copy link
Author

alexiri commented Nov 14, 2021

@Kludex I've added a test to demonstrate how h11 fails and another to show how the parameter fixes it. I wanted to actually assert the right exception, but the mock doesn't let it bubble up. Can you take a look and let me know what you think of this approach?

…n and the h11_max_incomplete_event_size parameter
Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

Maybe we should also add some information on the settings.md?

max_incomplete_event_size=config.h11_max_incomplete_event_size,
)
else:
self.conn = h11.Connection(h11.SERVER)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Maybe we should set the default ourselves instead of using the one h11 defines? Even if it's with the same value?

Just a thought.

Copy link
Author

Choose a reason for hiding this comment

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

I think it's better to respect the h11 default in case they change it for some reason.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I think the reason you mentioned is exactly why we should set it here 😅

Maybe we should check what hypercorn is doing here 🤔

Copy link
Author

Choose a reason for hiding this comment

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

Hypercorn sets it, but I think it's the wrong approach. If you're using h11, you should trust them to set their defaults correctly. If they change it, they probably have a good reason for doing so, like fixing a bug or implementing a new feature. If you're still using the old default, now you're affected by the bug they already fixed and you have to update your default as well.

Anyway, if you feel strongly about this, feel free to set the default directly. The code will certainly be cleaner.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

If they change it, they probably have a good reason for doing so, like fixing a bug or implementing a new feature.

I think we need to be in charge here. h11 can change their values as they want, they are on pre-stable release (I doubt they would, because this value is actually based on several other implementations).

Also, the code becomes cleaner anyway.

Would you mind changing it?

@Kludex
Copy link
Sponsor Member

Kludex commented Dec 2, 2021

btw, thanks for the PR! 🎉

@alexiri
Copy link
Author

alexiri commented Dec 4, 2021

Maybe we should also add some information on the settings.md?

Ok, done.

@Kludex
Copy link
Sponsor Member

Kludex commented Dec 4, 2021

@Kludex I've added a test to demonstrate how h11 fails and another to show how the parameter fixes it. I wanted to actually assert the right exception, but the mock doesn't let it bubble up. Can you take a look and let me know what you think of this approach?

Can't you do something like:

    with pytest.raises(AssertionError) as exc:
        assert exc.msg(?) == ??

Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

@alexiri Are you still interested in this PR?

@@ -50,6 +50,7 @@ By default Uvicorn uses simple changes detection strategy that compares python f
* `--ws-ping-interval <float>` - Set the WebSockets ping interval, in seconds. Please note that this can be used only with the default `websockets` protocol.
* `--ws-ping-timeout <float>` - Set the WebSockets ping timeout, in seconds. Please note that this can be used only with the default `websockets` protocol.
* `--lifespan <str>` - Set the Lifespan protocol implementation. **Options:** *'auto', 'on', 'off'.* **Default:** *'auto'*.
* `--h11-max-incomplete-event-size <int>` - For h11 protocol implementation, set the maximum number of bytes to buffer of an incomplete event.
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Suggested change
* `--h11-max-incomplete-event-size <int>` - For h11 protocol implementation, set the maximum number of bytes to buffer of an incomplete event.
* `--h11-max-incomplete-event-size <int>` - Set the maximum number of bytes to buffer of an incomplete event. Only available for `h11` HTTP protocol implementation.

@alexiri
Copy link
Author

alexiri commented Jan 27, 2022

Not really, no. Feel free to close it.

@doiko
Copy link

doiko commented Apr 13, 2022

Any plans to merge this one?

@Kludex
Copy link
Sponsor Member

Kludex commented Apr 13, 2022

Let's reevaluate over the issue.

@Kludex Kludex closed this Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting author Waiting for author's reply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants