mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Locking whil SyntaxCheck
This commit is contained in:
@@ -36,6 +36,7 @@ public class APIController : Controller {
|
||||
|
||||
// Options
|
||||
private static readonly FormOptions _defaultFormOptions = new FormOptions();
|
||||
private static readonly SemaphoreSlim _syntaxCheckLock = new SemaphoreSlim(1, 1);
|
||||
|
||||
|
||||
public APIController(IHaDocumentWrappper lib, IXMLInteractionService xmlService, IXMLFileProvider xmlProvider) {
|
||||
@@ -78,12 +79,21 @@ public class APIController : Controller {
|
||||
// [ValidateAntiForgeryToken]
|
||||
[DisableFormValueModelBinding]
|
||||
[FeatureGate(Features.SyntaxCheck, Features.AdminService)]
|
||||
public ActionResult<Dictionary<string, SyntaxCheckModel>?> GetSyntaxCheck(string? id) {
|
||||
public async Task<ActionResult<Dictionary<string, SyntaxCheckModel>?>> GetSyntaxCheck(string? id) {
|
||||
var SCCache = _xmlService.GetSCCache();
|
||||
if (_xmlProvider.HasChanged() || SCCache == null) {
|
||||
var commit = _xmlProvider.GetGitState();
|
||||
SCCache = _xmlService.Test(_xmlService.GetState(), commit != null ? commit.Commit : string.Empty);
|
||||
_xmlService.SetSCCache(SCCache);
|
||||
await _syntaxCheckLock.WaitAsync();
|
||||
try {
|
||||
// Double-check after acquiring lock
|
||||
SCCache = _xmlService.GetSCCache();
|
||||
if (_xmlProvider.HasChanged() || SCCache == null) {
|
||||
var commit = _xmlProvider.GetGitState();
|
||||
SCCache = _xmlService.Test(_xmlService.GetState(), commit != null ? commit.Commit : string.Empty);
|
||||
_xmlService.SetSCCache(SCCache);
|
||||
}
|
||||
} finally {
|
||||
_syntaxCheckLock.Release();
|
||||
}
|
||||
}
|
||||
return Ok(SCCache);
|
||||
}
|
||||
|
||||
@@ -81,13 +81,13 @@ public class WebSocketMiddleware : IMiddleware {
|
||||
}
|
||||
result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
|
||||
} catch (WebSocketException ex) {
|
||||
_openSockets!.Remove(webSocket);
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None);
|
||||
} catch (WebSocketException ex) {
|
||||
_openSockets.Remove(webSocket);
|
||||
// Socket already closed
|
||||
}
|
||||
_openSockets!.Remove(webSocket);
|
||||
}
|
||||
@@ -124,13 +124,17 @@ public class WebSocketMiddleware : IMiddleware {
|
||||
|
||||
private async Task _SendToAll<T>(T msg) {
|
||||
if (_openSockets == null) return;
|
||||
foreach (var socket in _openSockets) {
|
||||
var socketsToRemove = new List<WebSocket>();
|
||||
foreach (var socket in _openSockets.ToList()) {
|
||||
try {
|
||||
await socket.SendAsync(_SerializeToBytes(msg), WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
} catch (WebSocketException ex) {
|
||||
_openSockets.Remove(socket);
|
||||
socketsToRemove.Add(socket);
|
||||
}
|
||||
}
|
||||
foreach (var socket in socketsToRemove) {
|
||||
_openSockets.Remove(socket);
|
||||
}
|
||||
}
|
||||
|
||||
private ArraySegment<byte> _SerializeToBytes<T>(T o) {
|
||||
|
||||
@@ -2,10 +2,10 @@ name: hamann-ausgabe-staging
|
||||
services:
|
||||
hamann-staging:
|
||||
build: .
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- hamann_staging_data:/app/data
|
||||
networks:
|
||||
- caddy
|
||||
environment:
|
||||
- ASPNETCORE_URLS=http://+:5000
|
||||
- DOTNET_ENVIRONMENT=Staging
|
||||
@@ -18,7 +18,3 @@ services:
|
||||
volumes:
|
||||
hamann_staging_data:
|
||||
external: true
|
||||
|
||||
networks:
|
||||
caddy:
|
||||
external: true
|
||||
@@ -2,10 +2,10 @@ name: hamann-ausgabe
|
||||
services:
|
||||
hamann-service:
|
||||
build: .
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- hamann_data:/app/data
|
||||
networks:
|
||||
- caddy
|
||||
environment:
|
||||
- ASPNETCORE_URLS=http://+:5000
|
||||
- DOTNET_ENVIRONMENT=Production
|
||||
@@ -18,7 +18,3 @@ services:
|
||||
volumes:
|
||||
hamann_data:
|
||||
external: true
|
||||
|
||||
networks:
|
||||
caddy:
|
||||
external: true
|
||||
|
||||
Reference in New Issue
Block a user