GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-124309: fix staggered race on eager tasks by graingert · Pull Request #124847 · python/cpython Conversation
|
|
I'm marking this as |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Hopefully you will test with a range of aiohttp versions -- the previous version of this PR seemed to work on some but not on others. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yeah, that's the idea. We might not even need this PR if their new implementation turns out to work perfectly. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Don't we still need to do something to make eager tasks work? Or does that problem only occur in combination with aiohttp? Presumably there's at least one previous aiohttp version where the current main (or 3.12) branch doesn't work with aiohttp (or I don't understand the issue). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Our implementation (on main and 3.12) doesn't work with eager task factories, and most aiohttp versions (apart from the latest, IIUC, because they made their own) rely on our implementation. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
So we definitely have to change something right? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yup, I'm just cautious because I don't want to break prior aiohttp versions on accident. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ok_to_start = locks.Event() | ||
| first_task = loop.create_task(run_one_coro(ok_to_start, None)) | ||
| running_tasks.append(first_task) | ||
| ok_to_start.set() |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
For the first one, should the event be preset so it doesn't negate the benefits of an eager task factory?
Or maybe make the event optional for the first one since we want it to start right away?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
no it's still needed because all the coro_fn can return immediately without awaiting anything resulting in none of the tasks being appended to running_tasks
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
it's not terribly important to maintain the benefits of an eager task factory here as it's supposed to be used for happy_eyeballs over the internet where there is always going to be some delay
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I was only thinking about the first one since there is a chance the first ip could connect right away (not sure if it can happen synchronously or not)
In aiohttp we don't know if the host is an internet or lan or local host so everything ends up going through this path.
It's also possible the user connecting to localhost has working ipv4 but broken IPv6 and 127.0.0.1 will connect right away and ::1 never will or vise versa
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Even connecting to a localhost socket raises BlockingIOError and asyncio needs to wait for it to be writable
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the PR. I can test in production later this week |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
we should copy and adapt the aiohttp tests into cpython |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
sorry I pressed the wrong button |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Feel free to copy and adapt any tests in aiohappyeyeballs and consider their relicensed as needed for cpython |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I can get to porting aiohttp's pytest stuff over to us sometime later this week. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
The new implementation we have in aiohappyeyeballs seems to be going well. No new issues for aiohappyeyeballs filed, Home Assistant release went well, and my testing went well. I think I’m ready to start testing this PR today I’ll start by running aiohappyeyeballs test suite against it and if it passes try to write a meaningful benchmark to compare the implementations |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ok, good to know. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
FWIW it's a different systemic issue that we need to fix asap (and backport to 3.13) IMO this PR shouldn't solve that specific problem and focus on a smaller change. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@@ -139,3 +139,9 @@ async def staggered_race(coro_fns, delay, *, loop=None): # Make sure no tasks are left running if we leave this function for t in running_tasks: t.cancel() + try: + await t + except (SystemExit, KeyboardInterrupt): + raise + except BaseException: + pass That fixes the warning but still the aiohappyeyeballs cancellation swallow check test is failing |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes awaiting a task and suppressing cancellation will do that. You need to use a loop and a future. But we can fix that in another PR |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If aiohttp's implementation has been tested in production (and has all their tests passing), why not just copy theirs over? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Can you give a link to the final diff of their fix? I can't find it in the few links to different issues I clicked through this discussion. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hm, tbqh I think the approach in this PR is more straightforward. Unless you have a specific concern I'd go with it. @graingert feel free to go ahead and merge. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
We do need to backport this though. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I can't merge, I'll need a core dev to do it for me |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I'm worried about the failing tests on aiohttp's end, but I think Thomas said that he'll address that in another PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'll go ahead and approve this to ease stomachs about merging :)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Apologies, I'll go ahead and click the button then. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @graingert for the PR, and @1st1 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This patch is entirely by Thomas and Peter (cherry picked from commit 979c0df) Co-authored-by: Thomas Grainger <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
This patch is entirely by Thomas and Peter (cherry picked from commit 979c0df) Co-authored-by: Thomas Grainger <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
|
GH-125339 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-125340 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
) Co-authored-by: Thomas Grainger <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
) gh-124309: fix staggered race on eager tasks (GH-124847) This patch is entirely by Thomas and Peter (cherry picked from commit 979c0df) Co-authored-by: Thomas Grainger <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
related aiohttp issue aio-libs/aiohttp#10506 In #101 we replaced the staggered race implementation since the cpython version had races that were not fixed at the time. cpython has since updated the implementation to fix additional races. Our current implementation still has problems with cancellation and cpython has fixed that in python/cpython#128475 and python/cpython#124847 This PR ports the latest cpython implementation
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.