Skip to content

Make PoolManager.ClearAllPools remove pools#4722

Draft
Brar wants to merge 1 commit intonpgsql:mainfrom
Brar:RemovePoolsInClearAllPools
Draft

Make PoolManager.ClearAllPools remove pools#4722
Brar wants to merge 1 commit intonpgsql:mainfrom
Brar:RemovePoolsInClearAllPools

Conversation

@Brar
Copy link
Member

@Brar Brar commented Oct 15, 2022

Closes #3387

If I read the code correctly it is as simple as that. Narrator: "It wasn't."
I clearly must be missing something. Narrator: "Yes"

@Brar Brar requested review from roji and vonzshik as code owners October 15, 2022 14:52
@Brar Brar marked this pull request as draft October 16, 2022 13:23
@Brar Brar force-pushed the RemovePoolsInClearAllPools branch 2 times, most recently from 1929eaf to e61b9b4 Compare October 16, 2022 19:23
@Brar Brar marked this pull request as ready for review October 16, 2022 19:23
@roji roji mentioned this pull request Oct 20, 2022
@roji
Copy link
Member

roji commented Oct 20, 2022

We should have more narrator voices in our issues and PRs 🤣

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Here are some thoughts... @vonzshik would appreciate your thoughts here too since I don't have too much time to think/interact here, and there's some concurrency stuff which you're good at.

@Brar Brar closed this Oct 30, 2022
@vonzshik
Copy link
Contributor

@Brar just in case, did you intentionally close the pr?

@Brar
Copy link
Member Author

Brar commented Oct 30, 2022

@Brar just in case, did you intentionally close the pr?

Huh, no Idea how that happened.

@Brar Brar reopened this Oct 30, 2022
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

@vonzshik can you take a quick look as well for the concurrency intelligence? :)

_pools = new();
}
foreach (var pool in pools.Values)
pool.Dispose();
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a curious case with MultipleHosts. The way it's working right now is NpgsqlMultiHostDataSource has a list of MultiHostDataSourceWrapper which are actually referenced by connections. I think we shouldn't remove them from the pool here and instead do so in the NpgsqlMultiHostDataSource.Dispose.
Then there is also a question of calling Clear on MultiHostDataSourceWrapper...

Copy link
Member Author

Choose a reason for hiding this comment

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

As it currently stands, only NpgsqlDataSource implements Dispose() and that one calls Clear() which is implemented by the derived classes.
MultiHostDataSourceWrapper.Clear() currently calls Clear() on the wrapped NpgsqlMultiHostDataSource which then calls Clear() on all the Per-Host-Pools.

I don't see a problem with disposing whatever DataSource we have in the PoolManager.
Am I missing something again?

@Brar Brar force-pushed the RemovePoolsInClearAllPools branch from 1c0a934 to 0163c17 Compare October 30, 2022 23:24
}
// When using PoolManager (legacy code path setting NpgsqlConnection.ConnectionString), clearing a pool
// removes the pool (NpgsqlDataSource) from the PoolManager and disposes it.
// This leads to an ObjectDisposedException when calling NpgsqlDataSource.Get() here.
Copy link
Member

Choose a reason for hiding this comment

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

This is for making ReloadTypes work after Clear/ClearAll is called, when multiplexing is on, right (good catch)? If so maybe mention multiplexing in the comment to make this clearer.

Copy link
Member Author

@Brar Brar Oct 31, 2022

Choose a reason for hiding this comment

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

👍

// Force doing the startup checks again when disposed
// in order to reset the Connection's DataSource
if (disposing)
StartupCheckPerformed = false;
Copy link
Member

Choose a reason for hiding this comment

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

Can you provide a bit more context on why this is needed? AFAICT this flag is only consulted when opening the first connection on a multiplexing data source, I'm not sure why we'd need to reset it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the simplest solution to make things work if you call ReloadTypes after opening the first multiplexing connection.
Without it, you fail in the next command's execution after calling it and from there it it very hard to recover the DataSource.

@Brar Brar force-pushed the RemovePoolsInClearAllPools branch 4 times, most recently from 513c507 to ac912da Compare November 3, 2022 07:09
@Brar Brar force-pushed the RemovePoolsInClearAllPools branch from ac912da to e9ab0a8 Compare November 10, 2022 10:34
@Brar Brar marked this pull request as draft November 7, 2023 20:55
@roji
Copy link
Member

roji commented Nov 7, 2023

/cc @Brar, data source disposal seems to have been properly implemented, so this can be revisited.

@Brar Brar force-pushed the RemovePoolsInClearAllPools branch from e9ab0a8 to b063465 Compare January 18, 2024 12:39
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.

Make ClearAllPools complete remove pools from memory

3 participants