Skip to content

Commit

Permalink
Improve stability
Browse files Browse the repository at this point in the history
- adjust needs ctx creation to not access null Outputs github-act-runner
- adjust needs ctx creation, to keep failures even if later job succeeds
- fix race condition, where getmessage takes to long to abort
  GetMessage is now synchronized per session, to avoid loosing a job
  • Loading branch information
ChristopherHX committed Dec 23, 2021
1 parent fd95ce5 commit 9177468
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 246 deletions.
40 changes: 19 additions & 21 deletions src/Runner.Server/Controllers/AgentSessionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,35 @@ public async Task<IActionResult> Create(int poolId)
Value = _session.Agent.PublicKey.Encrypt(aes.Key, RSAEncryptionPadding.OaepSHA256)
};

MessageController.sessions.AddOrUpdate(_session, s => {
if(s.Timer == null) {
s.Timer = new System.Timers.Timer();
}
s.Timer.AutoReset = false;
s.Timer.Interval = 60000;
s.Timer.Elapsed += (a,b) => {
Session s2;
MessageController.sessions.TryRemove(_session, out s2);
};
s.Timer.Start();
return s;
} , (s, v) => {
s.Timer.Stop();
s.Timer.Start();
return v;
});
_session.Timer = new System.Timers.Timer();
_session.Timer.AutoReset = false;
_session.Timer.Interval = 60000;
_session.Timer.Elapsed += async (a,b) => {
await _session.MessageLock.WaitAsync(50000);
_session.DropMessage?.Invoke("Session deleted by Timeout");
_session.DropMessage = null;
_cache.Remove(session.SessionId);
_session.MessageLock.Dispose();
MessageController.sessions.TryRemove(_session, out _);
};
_session.Timer.Start();

MessageController.sessions.TryAdd(_session, _session);

return await Ok(session);
}

[HttpDelete("{poolId}/{sessionId}")]
public void Delete(int poolId, Guid sessionId)
public async Task Delete(int poolId, Guid sessionId)
{
Session session;
if(_cache.TryGetValue(sessionId, out session)) {
session.DropMessage?.Invoke();
await session.MessageLock.WaitAsync(50000);
session.DropMessage?.Invoke("Session deleted by Agent");
session.DropMessage = null;
_cache.Remove(sessionId);
Session s2;
MessageController.sessions.TryRemove(session, out s2);
session.MessageLock.Dispose();
MessageController.sessions.TryRemove(session, out _);
}
}
}
Expand Down
Loading

0 comments on commit 9177468

Please sign in to comment.