potential fix for downloads hanging at 0 bytes

This commit is contained in:
rootdarkarchon
2023-08-10 10:49:53 +02:00
parent 9307aaecac
commit b65ae8fca3
3 changed files with 25 additions and 18 deletions

View File

@@ -112,6 +112,8 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
return; return;
} }
_forceApplyMods |= forceApplyCustomization;
var charaDataToUpdate = characterData.CheckUpdatedData(applicationBase, _cachedData?.DeepClone() ?? new(), Logger, this, forceApplyCustomization, _forceApplyMods); var charaDataToUpdate = characterData.CheckUpdatedData(applicationBase, _cachedData?.DeepClone() ?? new(), Logger, this, forceApplyCustomization, _forceApplyMods);
if (_charaHandler != null && _forceApplyMods) if (_charaHandler != null && _forceApplyMods)
@@ -451,8 +453,6 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
}); });
_ipcManager.PenumbraAssignTemporaryCollectionAsync(Logger, _penumbraCollection, _charaHandler.GetGameObject()!.ObjectIndex).GetAwaiter().GetResult(); _ipcManager.PenumbraAssignTemporaryCollectionAsync(Logger, _penumbraCollection, _charaHandler.GetGameObject()!.ObjectIndex).GetAwaiter().GetResult();
_downloadManager.Initialize();
} }
private void IpcManagerOnPenumbraRedrawEvent(PenumbraRedrawMessage msg) private void IpcManagerOnPenumbraRedrawEvent(PenumbraRedrawMessage msg)

View File

@@ -8,7 +8,6 @@ using MareSynchronos.PlayerData.Handlers;
using MareSynchronos.Services.Mediator; using MareSynchronos.Services.Mediator;
using MareSynchronos.WebAPI.Files.Models; using MareSynchronos.WebAPI.Files.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Collections.Concurrent;
using System.Net; using System.Net;
using System.Net.Http.Json; using System.Net.Http.Json;
@@ -16,7 +15,6 @@ namespace MareSynchronos.WebAPI.Files;
public partial class FileDownloadManager : DisposableMediatorSubscriberBase public partial class FileDownloadManager : DisposableMediatorSubscriberBase
{ {
private readonly ConcurrentDictionary<Guid, bool> _downloadReady = new();
private readonly Dictionary<string, FileDownloadStatus> _downloadStatus; private readonly Dictionary<string, FileDownloadStatus> _downloadStatus;
private readonly FileCacheManager _fileDbManager; private readonly FileCacheManager _fileDbManager;
private readonly FileTransferOrchestrator _orchestrator; private readonly FileTransferOrchestrator _orchestrator;
@@ -60,17 +58,6 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
} }
} }
public void Initialize()
{
Mediator.Subscribe<DownloadReadyMessage>(this, (msg) =>
{
if (_downloadReady.ContainsKey(msg.RequestId))
{
_downloadReady[msg.RequestId] = true;
}
});
}
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
CancelDownload(); CancelDownload();
@@ -232,7 +219,6 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
Logger.LogDebug("Sent request for {n} files on server {uri} with result {result}", fileGroup.Count(), fileGroup.First().DownloadUri, requestIdResponse.Content.ReadAsStringAsync().Result); Logger.LogDebug("Sent request for {n} files on server {uri} with result {result}", fileGroup.Count(), fileGroup.First().DownloadUri, requestIdResponse.Content.ReadAsStringAsync().Result);
Guid requestId = Guid.Parse(requestIdResponse.Content.ReadAsStringAsync().Result.Trim('"')); Guid requestId = Guid.Parse(requestIdResponse.Content.ReadAsStringAsync().Result.Trim('"'));
_downloadReady[requestId] = false;
Logger.LogDebug("GUID {requestId} for {n} files on server {uri}", requestId, fileGroup.Count(), fileGroup.First().DownloadUri); Logger.LogDebug("GUID {requestId} for {n} files on server {uri}", requestId, fileGroup.Count(), fileGroup.First().DownloadUri);
@@ -367,7 +353,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
localTimeoutCts.CancelAfter(TimeSpan.FromSeconds(5)); localTimeoutCts.CancelAfter(TimeSpan.FromSeconds(5));
CancellationTokenSource composite = CancellationTokenSource.CreateLinkedTokenSource(downloadCt, localTimeoutCts.Token); CancellationTokenSource composite = CancellationTokenSource.CreateLinkedTokenSource(downloadCt, localTimeoutCts.Token);
while (_downloadReady.TryGetValue(requestId, out bool isReady) && !isReady) while (!_orchestrator.IsDownloadReady(requestId))
{ {
try try
{ {
@@ -420,7 +406,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
// ignore whatever happens here // ignore whatever happens here
} }
} }
_downloadReady.Remove(requestId, out _); _orchestrator.ClearDownloadRequest(requestId);
} }
} }
} }

View File

@@ -3,6 +3,7 @@ using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration; using MareSynchronos.Services.ServerConfiguration;
using MareSynchronos.WebAPI.Files.Models; using MareSynchronos.WebAPI.Files.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Collections.Concurrent;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Net.Http.Json; using System.Net.Http.Json;
using System.Reflection; using System.Reflection;
@@ -17,6 +18,7 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
private readonly ServerConfigurationManager _serverManager; private readonly ServerConfigurationManager _serverManager;
private int _availableDownloadSlots; private int _availableDownloadSlots;
private SemaphoreSlim _downloadSemaphore; private SemaphoreSlim _downloadSemaphore;
private readonly ConcurrentDictionary<Guid, bool> _downloadReady = new();
public FileTransferOrchestrator(ILogger<FileTransferOrchestrator> logger, MareConfigService mareConfig, ServerConfigurationManager serverManager, MareMediator mediator) : base(logger, mediator) public FileTransferOrchestrator(ILogger<FileTransferOrchestrator> logger, MareConfigService mareConfig, ServerConfigurationManager serverManager, MareMediator mediator) : base(logger, mediator)
{ {
@@ -39,6 +41,10 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
{ {
FilesCdnUri = null; FilesCdnUri = null;
}); });
Mediator.Subscribe<DownloadReadyMessage>(this, (msg) =>
{
_downloadReady[msg.RequestId] = true;
});
} }
public Uri? FilesCdnUri { private set; get; } public Uri? FilesCdnUri { private set; get; }
@@ -50,6 +56,21 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
_downloadSemaphore.Release(); _downloadSemaphore.Release();
} }
public bool IsDownloadReady(Guid guid)
{
if (_downloadReady.TryGetValue(guid, out bool isReady) && isReady)
{
return true;
}
return false;
}
public void ClearDownloadRequest(Guid guid)
{
_downloadReady.Remove(guid, out _);
}
public async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, Uri uri, CancellationToken? ct = null) public async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, Uri uri, CancellationToken? ct = null)
{ {
using var requestMessage = new HttpRequestMessage(method, uri); using var requestMessage = new HttpRequestMessage(method, uri);