mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-04-18 01:12:22 +03:00
Fix code for reducing chance of SQLite connection pool livelocks
This commit is contained in:
parent
cd418f4871
commit
d463b407f4
@ -45,22 +45,21 @@ namespace DHT.Server.Database.Sqlite.Utils {
|
||||
}
|
||||
|
||||
public ISqliteConnection Take() {
|
||||
PooledConnection? conn = null;
|
||||
|
||||
while (conn == null) {
|
||||
while (true) {
|
||||
ThrowIfDisposed();
|
||||
|
||||
lock (monitor) {
|
||||
if (free.TryTake(out conn, TimeSpan.FromMilliseconds(rand.Next(100, 200)))) {
|
||||
if (free.TryTake(out var conn)) {
|
||||
used.Add(conn);
|
||||
break;
|
||||
return conn;
|
||||
}
|
||||
else {
|
||||
Log.ForType<SqliteConnectionPool>().Warn("Thread " + Thread.CurrentThread.ManagedThreadId + " is starving for connections.");
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(TimeSpan.FromMilliseconds(rand.Next(100, 200)));
|
||||
}
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
private void Return(PooledConnection conn) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user