Skip to content

Commit 7b208cd

Browse files
Dirty memory check may fail connecting to RavenDB when using external mode (#4917)
* Favor connection string over server URL when trying to connect to RavenDB to retrieve dirty memory details * Update comment to reflect reality * Update audit comment --------- Co-authored-by: Brandon Ording <[email protected]>
1 parent b523b71 commit 7b208cd

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ namespace ServiceControl.Audit.Persistence.RavenDB;
88

99
class MemoryInformationRetriever(DatabaseConfiguration databaseConfiguration)
1010
{
11-
// What does a connection string look like? Is it only a URI or could it contain other stuff?
12-
// The ?? operator is needed because ServerUrl is populated when running embedded and connection
13-
// string when running in external mode. However, the tricky part is that when tests are run they
14-
// behave like if it was external mode. If the connection string contain always only the server
15-
// URL, this code is safe, otherwise it need to be adjusted to extract the server URL.
16-
readonly HttpClient client = new() { BaseAddress = new Uri(databaseConfiguration.ServerConfiguration.ServerUrl ?? databaseConfiguration.ServerConfiguration.ConnectionString) };
11+
// Connection string is composed of the server URL. The ?? operator is needed because ServerUrl
12+
// is populated when running embedded and connection string when running in external mode.
13+
// However, the tricky part is that when tests are run they behave like if it was external mode.
14+
// Only one of ConnectionString and ServerUrl will be non-null, so we'll check ConnectionString first
15+
// to be consistent with the error instance implementation, where ServerUrl always has a value.
16+
readonly HttpClient client = new() { BaseAddress = new Uri(databaseConfiguration.ServerConfiguration.ConnectionString ?? databaseConfiguration.ServerConfiguration.ServerUrl) };
1717

1818
record ResponseDto
1919
{

src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ namespace ServiceControl.Persistence.RavenDB;
88

99
class MemoryInformationRetriever(RavenPersisterSettings persisterSettings)
1010
{
11-
// What does a connection string look like? Is it only a URI or could it contain other stuff?
12-
// The primary instance has only the concept of a connection string (vs the Audit instance having
13-
// both a ServiceUrl and a ConnectionString). If the connection string contain always only the
14-
// server URL, this code is safe, otherwise it need to be adjusted to extract the server URL.
15-
readonly HttpClient client = new() { BaseAddress = new Uri(persisterSettings.ServerUrl ?? persisterSettings.ConnectionString) };
11+
// Connection string is composed of the server URL. The ?? operator is needed because ServerUrl
12+
// is populated when running embedded and connection string when running in external mode.
13+
// However, the tricky part is that when tests are run they behave like if it was external mode.
14+
// ServerUrl is always populated by the persister settings, hence the code first checks for the
15+
// presence of a connection string, and if null, falls back to ServerUrl
16+
readonly HttpClient client = new() { BaseAddress = new Uri(persisterSettings.ConnectionString ?? persisterSettings.ServerUrl) };
1617

1718
record ResponseDto
1819
{

0 commit comments

Comments
 (0)