aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-11-15 16:50:45 -0600
committerGitHub <noreply@github.com>2026-11-15 16:50:45 -0600
commitcbf32079d0f479b5f75f51cd24e04df33b2f4dd5 (patch)
treeb29f0a43c8bbe53dd58c0e1b16a3dff90b77d172
parent15b7021c395b5e91bf6a748d4537f0a7c4601130 (diff)
parent7d67dc1d6a452812981d6a0965c3a2e07737b726 (diff)
downloadslskd-cbf32079d0f479b5f75f51cd24e04df33b2f4dd5.tar.gz
Merge branch 'master' into more-bugs
-rw-r--r--src/slskd/Program.cs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 879f76b7..57d967f0 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -57,6 +57,7 @@ namespace slskd
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core;
+ using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -278,6 +279,7 @@ namespace slskd
private static Mutex Mutex { get; set; }
private static IDisposable DotNetRuntimeStats { get; set; }
private static VolatileOverlayConfigurationSource<OptionsOverlay> VolatileOverlayConfigurationSource { get; set; } = new VolatileOverlayConfigurationSource<OptionsOverlay>();
+ private static List<SqliteConnection> VolatileDatabaseKeepaliveConnections { get; } = [];
[Argument('g', "generate-cert", "generate X509 certificate and password for HTTPs")]
private static bool GenerateCertificate { get; set; }
@@ -747,7 +749,7 @@ namespace slskd
var pooling = OptionsAtStartup.Flags.NoSqlitePooling ? "False" : "True"; // don't invert and ToString this it is confusing
var connStr = OptionsAtStartup.Flags.Volatile
- ? $"Data Source=file:{database}?mode=memory;Pooling={pooling};"
+ ? $"Data Source=file:{database}?mode=memory&cache=shared;Pooling={pooling};"
: $"Data Source={Path.Combine(DataDirectory, $"{database}.db")};Pooling={pooling}";
return new KeyValuePair<Database, ConnectionString>(database, connStr);
@@ -1526,6 +1528,17 @@ namespace slskd
}
});
+ // in-memory databases are destroyed when the last connection to them closes. hold one open for the
+ // lifetime of the application so the data (and schema) survive between operations. this must be
+ // opened before EnsureCreated(), otherwise the schema is created in a database that is destroyed
+ // as soon as EnsureCreated() closes its connection
+ if (OptionsAtStartup.Flags.Volatile)
+ {
+ var keepalive = new SqliteConnection(connectionString);
+ keepalive.Open();
+ VolatileDatabaseKeepaliveConnections.Add(keepalive);
+ }
+
/*
instantiate the DbContext and make sure it is created
*/