mysticmind / mysticmind-postgresembed

Postgres embedded server equivalent including extensions for .Net applications
MIT License
143 stars 26 forks source link

Start hangs if locale is not English #18

Closed e-tobi closed 2 years ago

e-tobi commented 2 years ago

Starting the server hangs while waiting for "database system is ready to accept connections" in STDOUT from the PostgreSQL server. Worked fine on Linux, but on a German Windows 10 the output is "Datenbanksystem ist bereit, um Verbindungen anzunehmen", so the start task never ends.

I couldn't figure out how to tweak the output languang of postgres.exe. I've tried setting LANG, LC_ALL and LC_MESSAGES in the environment variables, but Postgres always writes German messages.

Maybe it would be better to wait for the server by trying to connect to it. Something like:

using var tcpClient = new TcpClient();
try
{
    var connectTask = tcpClient.ConnectAsync("127.0.0.1", Configuration.Port);
    var timeoutTask = Task.Delay(TimeSpan.FromSeconds(30));
    await Task.WhenAny(connectTask, timeoutTask).ConfigureAwait(false);
    if (connectTask.IsCompletedSuccessfully && !serverProcess.HasExited) return;
}
catch
{
    // ignored
}

throw new Exception($"Failed to start Postgres");

(Not a complete solution - needs to take care of the server process ending before the timeout and setting the Running status property - but you get the idea - I can provide a PR if you like.)

mysticmind commented 2 years ago

I will have look during my day tomorrow and keep you posted.

mysticmind commented 2 years ago

@e-tobi waiting for server startup is already there and the default wait time is 10secs. I can expose the property for end users to set a the wait time like say 30 secs.

e-tobi commented 2 years ago

Sorry! I've posted this to the totally wrong project! This issue was meant for https://github.com/atrauzzi/protoculture-dotnet-postgres. mysticmind-postgresembed works just fine, but I needed a solution to run on Linux as well.