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

Fixed #313, remove stack when empty #334

Merged
merged 1 commit into from
Sep 13, 2018
Merged

Fixed #313, remove stack when empty #334

merged 1 commit into from
Sep 13, 2018

Conversation

fantix
Copy link
Member

@fantix fantix commented Sep 10, 2018

  1. I found that it is not possible to use ctx.reset(token), because for now we allow releasing connections in different order, and possibly in different tasks:
async def task1():
    async with engine.acquire() as conn1:
        loop.create_task(task2())
        await asyncio.sleep(1)
    
async def task2():
    async with engine.acquire() as conn2:
        await asyncio.sleep(2)

asyncio.run(task1())

In this case, both tasks are sharing the same stack, but not reusing each other. The stack was created in task1, but cleared out in task2. ContextVar.reset(token) requires that the given token was created in the same context (task), therefore cannot be used in this PR.

  1. There was another approach to create a new empty stack on acquire() if the current one is empty. Other than resource waste, there was another reason came to me not to do so, but as writing this PR I cannot remember the reason :sigh

@fantix fantix requested a review from wwwjfy September 10, 2018 07:54
@coveralls
Copy link

Pull Request Test Coverage Report for Build 1186

  • 49 of 49 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 98.263%

Totals Coverage Status
Change from base Build 1184: 0.01%
Covered Lines: 3961
Relevant Lines: 4031

💛 - Coveralls

@wwwjfy
Copy link
Member

wwwjfy commented Sep 12, 2018

I haven't tried, but I think using 2. in the description, while the first task is getting the connection, the second task may find the stack created by the first task is empty then remove it?

Copy link
Member

@wwwjfy wwwjfy left a comment

Choose a reason for hiding this comment

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

👏

@fantix
Copy link
Member Author

fantix commented Sep 13, 2018

Yeah it was very much that. Thanks!

@fantix fantix merged commit 4828084 into master Sep 13, 2018
@fantix fantix deleted the t313 branch September 13, 2018 02:12
@fantix fantix modified the milestones: v0.8.x, v0.7.x Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants