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

Do not dispose EF Core contexts manually #15649

Conversation

bergmania
Copy link
Member

Simple PR that removes the functionality that disposes a EF Core context when the connection string changes.

Fixes: #15090 (Again)

Background

Some people still have timing issues when installing, because the EF Core context is disposed.
The reason is because IOptionsMonitor can call the OnChange event even that it have read the correct value some time before.

So the timing issue happens, if the UmbracoDbContext is constructed just after the connection string is updated in the json file. Then the constructor reads the updated value, but afterwards the onChange is called, even that it did not really change anything (Since the creation).

We should be safe, because an earlier PR throws an exception from the constructor, if the connection string do not exists.

After this PR, UmbracoDbContext initialised with a connection string will continue to work with that connection string until disposed.

A Ef core context is protected from creations when no connection string is present. If it changes that single instance will continue with the connection string it was initialized with.
…string-and-only-dispose-if-it-have-been-updated' into v13/bugfix/15090-save-connectionstring-and-only-dispose-if-it-have-been-updated

# Conflicts:
#	src/Umbraco.Cms.Persistence.EFCore/UmbracoDbContext.cs
Copy link
Contributor

@kjac kjac left a comment

Choose a reason for hiding this comment

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

💪

@bergmania bergmania merged commit 5146f05 into v13/dev Jan 31, 2024
16 checks passed
@bergmania bergmania deleted the v13/bugfix/15090-save-connectionstring-and-only-dispose-if-it-have-been-updated branch January 31, 2024 14:09
bergmania added a commit that referenced this pull request Jan 31, 2024
* Attempt to fix #15090. Save connection string in private variable after setup.

* Do not dispose ef core contexts when if the connectionstring changes.

A Ef core context is protected from creations when no connection string is present. If it changes that single instance will continue with the connection string it was initialized with.

* Clean up

* Review Equals methods

(cherry picked from commit 5146f05)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants