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

On startup if Umbraco cannot connect to the database, it always opens the installer #12949

Closed
joepvtl opened this issue Sep 5, 2022 · 20 comments

Comments

@joepvtl
Copy link
Contributor

joepvtl commented Sep 5, 2022

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

10.1.0

Bug summary

When Umbraco can't connect to the database, the installer page opens even if the Umbraco environment was already configured.

Specifics

Using the Provider: Microsoft.Data.SqlClient

[11:27:08 DBG] Could not immediately connect to database, trying again.
[11:27:09 WRN] Configured database is reporting as not being available.
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
 ---> System.ComponentModel.Win32Exception (53): The network path was not found.
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
   at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
   at Microsoft.Data.SqlClient.SqlConnection.Open()
   at Umbraco.Extensions.DbConnectionExtensions.IsAvailable(IDbConnection connection)
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:53,State:0,Class:20
[11:27:09 DBG] Could not connect to database.
[11:27:09 DBG] Runtime level: Install - InstallMissingDatabase

I think this bug got introduced in this commit: 8e6e262#diff-6ac9a3ad41721ad6c1743713a759eef7e43bd731f3ce6294023d2af3b7e7dd0eL146

Steps to reproduce

  1. Setup a Umbraco environment with SQL server that doesn't run on your localdb.
  2. Now change the server part in the connectionstring to a domain that doesn't exist for example: test.test
  3. Restart your Umbraco environment and the install page should show.

Expected result / actual result

Expected
I expect to see a 500 page with the message: "A connection string is configured but Umbraco could not connect to the database." like in Umbraco 9.

Actual
Actual result is a installer page that everyone can see.


This item has been added to our backlog AB#22604

@github-actions
Copy link

github-actions bot commented Sep 5, 2022

Hi there @joepvtl!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@nul800sebastiaan
Copy link
Member

I haven't tried this yet, does sound like a bug, but I am a bit curious as to what the use case is here? I understand your example is made for us to be able to reproduce it, but what are you actually trying to accomplish by changing the connection string?

@nul800sebastiaan nul800sebastiaan added the state/needs-more-info We don't have enough information to give a good reply label Sep 6, 2022
@joepvtl
Copy link
Contributor Author

joepvtl commented Sep 6, 2022

Its just an example to reproduce for when Umbraco can't reach your database, when your database server is offline or has a a hiccup. In earlier versions Umbraco would just show a 500 page, but now it opens up the installer which everyone can see and configure. I feel like this should never just happen when the database can't be reached.

@nul800sebastiaan
Copy link
Member

Yes, that is a good point, shouldn't jump to the installer if the database can't be reached, didn't think of that, thanks! We'll have a look.

@nul800sebastiaan nul800sebastiaan added state/needs-investigation This requires input from HQ or community to proceed and removed state/needs-more-info We don't have enough information to give a good reply labels Sep 6, 2022
@nul800sebastiaan
Copy link
Member

I can reproduce the behavior in v10.0.1 and also in v9.0.1 as well, so it hasn't changed in the referred commit above.

@joepvtl
Copy link
Contributor Author

joepvtl commented Sep 6, 2022

When I tested this in v9 It does have the expected behaviour in v9.5.4

[10:48:24 DBG] Could not immediately connect to database, trying again.
[10:48:25 WRN] Configured database is reporting as not being available.
System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
 ---> System.ComponentModel.Win32Exception (53): The network path was not found.
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at Umbraco.Extensions.DbConnectionExtensions.IsAvailable(IDbConnection connection)
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:53,State:0,Class:20
[10:48:25 DBG] Could not connect to database.
[10:48:25 ERR] Boot Failed
Umbraco.Cms.Core.Exceptions.BootFailedException: A connection string is configured but Umbraco could not connect to the database.
   at Umbraco.Cms.Infrastructure.Runtime.RuntimeState.DetermineRuntimeLevel()
   at Umbraco.Cms.Infrastructure.Runtime.CoreRuntime.DetermineRuntimeLevel()

@nul800sebastiaan
Copy link
Member

Hmmm, this is what I'm seeing:

12949.mp4

But maybe this is specifically about SQL Server, I didn't test that.

@joepvtl
Copy link
Contributor Author

joepvtl commented Sep 6, 2022

Yeah this scenario does exist in v9 when the connectionstring has the value localdb in it (see this line) But I guess that was intended behaviour because in the commit I referred to, the old code did check for that value and if it has that value, it sets the state to InstallMissingDatabase. But now it always does this.

@nul800sebastiaan
Copy link
Member

So I just tried the exact scenario from the video above in 9.5.4, but I used SQL Server this time. I stopped the site, changed the server from localhost to test.test and started the site again, it launches into the Umbraco installer screen, like above.

@nul800sebastiaan
Copy link
Member

In 10.1.1 when I stop the server so that it can't be reached any more, while the site is running, I get the expected error, and that is also what you were expecting to see

when Umbraco can't reach your database, when your database server is offline or has a a hiccup. In earlier versions Umbraco would just show a 500 page

image

@joepvtl
Copy link
Contributor Author

joepvtl commented Sep 6, 2022

Yeah the issue is only on boot, not when the site is already running.

@rammi987
Copy link
Contributor

rammi987 commented Sep 7, 2022

@nul800sebastiaan Meaby this can help.

When you have an Connectionstring, witch are not null or empty, we end here
https://github.com/umbraco/Umbraco-CMS/blob/v10/contrib/src/Umbraco.Infrastructure/Runtime/RuntimeState.cs#L213

as for the Global setting InstallMissingDatabase is per default false in 9 and 10, but if we take a closer look into _databaseProviderMetadata.CanForceCreateDatabase(_databaseFactory.ProviderName) there is the iconicity happing.

https://github.com/umbraco/Umbraco-CMS/blob/v10/contrib/src/Umbraco.Cms.Persistence.SqlServer/Services/SqlLocalDbDatabaseProviderMetadata.cs#L52
https://github.com/umbraco/Umbraco-CMS/blob/v10/contrib/src/Umbraco.Cms.Persistence.SqlServer/Services/SqlAzureDatabaseProviderMetadata.cs#L51
https://github.com/umbraco/Umbraco-CMS/blob/v10/contrib/src/Umbraco.Cms.Persistence.SqlServer/Services/SqlServerDatabaseProviderMetadata.cs#L50
https://github.com/umbraco/Umbraco-CMS/blob/v10/contrib/src/Umbraco.Cms.Persistence.Sqlite/Services/SqliteDatabaseProviderMetadata.cs#L46

I testede with the Sqlite where I changes the database name to get an invalid connection string, but ended on the install page. _databaseProviderMetadata.CanForceCreateDatabase(_databaseFactory.ProviderName) is returning true, due to hardcoded force at https://github.com/umbraco/Umbraco-CMS/blob/v10/contrib/src/Umbraco.Cms.Persistence.Sqlite/Services/SqliteDatabaseProviderMetadata.cs#L46

For Umbraco 9.
https://github.com/umbraco/Umbraco-CMS/blob/v9/dev/src/Umbraco.Infrastructure/Runtime/RuntimeState.cs#L313

In 9 and 10, if using either Sqlite or SQL Server Express LocalDB it will end up in install page.

@JoseMarcenaro
Copy link
Contributor

JoseMarcenaro commented Sep 9, 2022

I can confirm this is still happening in v10.1.0 and v10.2.0
It's a misleading behavior when connectivity with the SQL server is broken due to any reason - i.e. firewall issues on Azure.

@lassefredslund lassefredslund added the state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks label Sep 14, 2022
@nul800sebastiaan
Copy link
Member

nul800sebastiaan commented Sep 14, 2022

For the team at HQ, I'll summarize the problem here:

  • Your SQL server connection goes down for any reason
  • AND your site restarts for any reason
  • Umbraco will think it's not installed

This is not correct, Umbraco does have a configured connection string and therefore should simply give the error that no connection can be made to the database.

We've added it to our backlog to look at in the next few weeks and will keep this issue updated.

@gilbertaoe
Copy link
Contributor

gilbertaoe commented Sep 22, 2022

@nul800sebastiaan @joepvtl @JoseMarcenaro I saw a separate open issue with this same problem yesterday and didn't realize it was a duplicate. I've already made the fix and created a pull request. I accidentally added this issue's link to the wrong pull request... so ignore the mention of the X-XSS-Protection pull request :p

I was able to replicate the issue with any bad connection, Azure firewall or not, and after making the changes in the pull request I get a error page with details of the error instead of the install screen.

Pull request: #13045
Duplicate Issue: #13042

@gilbertaoe
Copy link
Contributor

gilbertaoe commented Sep 22, 2022

@nul800sebastiaan to clarify the issue further if it helps, for 10.2.0, I could only replicate if I stopped and started the app pool. If I didn't restart the app pool, due to the nature of Umbraco's Backoffice, restricting the database's firewall didn't immediately cause any issues or for the installer to trigger

@JoseMarcenaro
Copy link
Contributor

In my case (Azure with slots) the issue happens when swapping the slots, if for some reason the DB is out of reach (i.e. misconfigured network firewall)

@gilbertaoe
Copy link
Contributor

This should "fix" that problem for you... it will show you an error pge that the DB is out of reach, but it won't prompt you to re-install.

@JoseMarcenaro
Copy link
Contributor

Thank @gilbertaoe . Reaching the Install page is really bad, because once you did, you are stuck there even after you have restored the DB connectivity.
As far as I know, you need to manually empty the /umbraco/data folder to get rid of the install stuff.

@nul800sebastiaan nul800sebastiaan added community/pr and removed state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks labels Sep 28, 2022
@kjac
Copy link
Contributor

kjac commented Dec 13, 2022

Whoops this one was fixed in #13118 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants