Skip to content

Commit e891996

Browse files
strangelydimclaude
andcommitted
Keep EmbeddedArchive probe open to prevent AWAIT_PUBLICATION_CONNECTED race
The WaitForArchiveReady probe was disposed immediately after confirming the archive was up. On Windows CI this created a race: between REMOVE_PUBLICATION (from the probe) and the test's own ADD_PUBLICATION, the archive briefly had no subscriber on its control channel and stopped sending Status Messages. The new publication would then timeout after 10s at AWAIT_PUBLICATION_CONNECTED. Fix: store the probe AeronArchive as a field and keep it alive for the full lifetime of the EmbeddedArchive instance. The probe is disposed in Dispose() after the JVM is killed (where it's safe and fast since OwnsAeronClient=false), and in KillProcess() before killing so pub/sub are cleanly removed first. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a5dc720 commit e891996

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/Adaptive.Archiver.IntegrationTests/Infrastructure/EmbeddedArchive.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ internal sealed class EmbeddedArchive : IDisposable
4949

5050
private readonly Process _archive;
5151
private readonly string _archiveDir;
52+
private AeronArchive _probeClient;
5253

5354
public bool PreserveArchiveDirOnDispose { get; set; }
5455

@@ -153,6 +154,11 @@ public AeronArchive.Context CreateClientContext(string aeronDirectoryName) =>
153154
/// </summary>
154155
public void KillProcess()
155156
{
157+
// Dispose the probe before killing the JVM so its pub/sub are cleanly removed
158+
// from the conductor before the process disappears under them.
159+
try { _probeClient?.Dispose(); } catch { }
160+
_probeClient = null;
161+
156162
ShutdownProcess(_archive, "EmbeddedArchive");
157163

158164
try
@@ -172,6 +178,11 @@ public void Dispose()
172178
{
173179
ShutdownProcess(_archive, "EmbeddedArchive");
174180

181+
// Dispose the probe after the JVM is dead so there is no window between
182+
// REMOVE_PUBLICATION and a subsequent ADD_PUBLICATION to the same channel.
183+
try { _probeClient?.Dispose(); } catch { }
184+
_probeClient = null;
185+
175186
bool exited = false;
176187
try { exited = _archive.HasExited; } catch { }
177188

@@ -251,7 +262,11 @@ private void WaitForArchiveReady(string aeronDirectoryName, AeronClient aeronCli
251262
{
252263
ctx.AeronClient(aeronClient);
253264
}
254-
using var client = AeronArchive.Connect(ctx);
265+
// Keep the probe open for the lifetime of this EmbeddedArchive instance.
266+
// Disposing it immediately creates a window between REMOVE_PUBLICATION and
267+
// the test's own ADD_PUBLICATION where the archive sees no subscriber and
268+
// won't send Status Messages, causing AWAIT_PUBLICATION_CONNECTED timeouts.
269+
_probeClient = AeronArchive.Connect(ctx);
255270
return;
256271
}
257272
catch (Exception e)

0 commit comments

Comments
 (0)