Problem: my connection to a locally stored EventStore is not being maintained when I debug my .NET application from Visual Studio.
I get an error:
Connection 'ES-6ab8f860-e44b-40ca-93fa-7370b72547d8' was closed.
Current setup: my Event Store is placed in my solution, application referenced by a PATH variable.
//Path to the local EventStore in solution
private const string Path = @"..\..\EventStore-OSS-Win-v5.0.8\EventStore.ClusterNode.exe";
The following code setups a new connection to the EventStore:
public static void SetupEventStore(StartConflictOption opt = StartConflictOption.Connect) //set default to Connect
{
// Save the EventStore process in a variable for later use
var runningEventStores = Process.GetProcessesByName("EventStore.ClusterNode");
// if a process was found, check the parameter options on what to do with the process
if (runningEventStores.Length != 0)
{
switch (opt)
{
case StartConflictOption.Connect:
_process = runningEventStores[0]; //set the process to the EventStore.ClusterNode
break;
case StartConflictOption.Kill:
foreach (var es in runningEventStores) //makes sure that all running processes are killed
{
es.Kill();
}
break;
case StartConflictOption.Error:
throw new Exception("Conflicting EventStore running."); //Will be thrown if there is already a running EventStore process
default:
throw new ArgumentOutOfRangeException(nameof(opt), opt, null);
}
}
if (_process == null)
{
_process = new Process
{
StartInfo =
{
UseShellExecute = false, CreateNoWindow = true, FileName = Path, Arguments = Args, Verb = "runas"
}
};
_process.Start();
}
//set default IP endpoint and port (localhost:1113). HTTP uses port 2113, while TCP uses port 1113
var tcp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113);
var http = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2113);
//Connect to the Event Store
Connection = EventStoreConnection.Create(new Uri("tcp://admin:changeit@localhost:1113"));
Connection.ConnectAsync().Wait();
}
When I debug the application, it starts up without issues, but when I attempt to create a new stream to the EventStore, it crashes with the previously mentioned error.
I noticed that the EventStore process is active for a split second, before being terminated when debugging the application.
Question: why is my Event Store process not being maintained while the application is running and what steps can I take to fix this issue?