Skip to content

Commit

Permalink
Lock on connection. Fix logout timer with pings
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Mar 24, 2024
1 parent 478d5e3 commit 9a79256
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Shoko.Server/Providers/AniDB/UDP/Connection/RequestPing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void PreExecute(string sessionID)

public override UDPResponse<Void> Send()
{
var rawResponse = Handler.SendDirectly(BaseCommand, resetPingTimer: false).Result;
var rawResponse = Handler.SendDirectly(BaseCommand, resetPingTimer: false, resetLogoutTimer: false).Result;
var response = ParseResponse(rawResponse);
var parsedResponse = ParseResponse(response);
return parsedResponse;
Expand Down
15 changes: 15 additions & 0 deletions Shoko.Server/Scheduling/ThreadPooledJobStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Quartz.Spi;
using Shoko.Server.Scheduling.Acquisition.Filters;
using Shoko.Server.Scheduling.Concurrency;
using Shoko.Server.Scheduling.DatabaseLocks;
using Shoko.Server.Scheduling.Delegates;
using Shoko.Server.Settings;
using Shoko.Server.Utilities;
Expand Down Expand Up @@ -93,6 +94,20 @@ private void InitConcurrencyCache()
foreach (var filter in _acquisitionFilters) filter.StateChanged -= FilterOnStateChanged;
}

// These two should be called in equal amounts, so no worry of deadlock
protected override ConnectionAndTransactionHolder GetNonManagedTXConnection()
{
if (LockHandler is SQLiteSemaphore) LockHandler.ObtainLock(Guid.Empty, null, LockTriggerAccess).GetAwaiter().GetResult();
return base.GetNonManagedTXConnection();
}

protected override void CleanupConnection(ConnectionAndTransactionHolder conn)
{
if (conn == null) return;
if (LockHandler is SQLiteSemaphore) LockHandler.ReleaseLock(Guid.Empty, LockTriggerAccess).GetAwaiter().GetResult();
CloseConnection(conn);
}

private void FilterOnStateChanged(object sender, EventArgs e)
{
SignalSchedulingChangeImmediately(new DateTimeOffset(1982, 6, 28, 0, 0, 0, TimeSpan.FromSeconds(0)));
Expand Down

0 comments on commit 9a79256

Please sign in to comment.