InvalidOperationException: Environment variable HOME not defined
See original GitHub issueGreetings,
There appears to be a hard requirement for npgsql to have an environment variable HOME defined in a specific setup. Is this a bug?
I’m running npgsql 5.0.5 in a C# dotnet core 3.1 project in a AWS lambda container. The aws lambda environment is Amazon Linux 2 and it does not specify a HOME variable. A home directory doesn’t exist.
Stack trace:
...\Database\PostgresClient.cs:line 52System.InvalidOperationException: Environment variable HOME not defined
at Npgsql.PostgresEnvironment.GetHomeDir()
at Npgsql.PostgresEnvironment.GetHomePostgresDir()
at Npgsql.PostgresEnvironment.get_SslCertDefault()
at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.ConnectorPool.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.ConnectorPool.<>c__DisplayClass38_0.<<Rent>g__RentAsync|0>d.MoveNext()
It appears that npgsql is just looking for a cert bundle? I tried providing a local cert bundle and providing the location in the connection string and it didn’t help. I can get around the issue by specifying the HOME variable to a temporary directory which works around the issue.
if (IsLambdaRunningInAwsContainer()) Environment.SetEnvironmentVariable("HOME", "/tmp");
With this work around I don’t need to provide my own cert bundle - it seem that npgsql can still find it on the instance.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Not really… I guess I just assumed these environment variables are always present (which is almost always the case 😅).
Submitted #3730 to fix.
Great, I used the CI version and it worked as expected. Thank you very much for the work and the quick responses. I will monitor to upgrade to the normal version instead of the CI. Hope you have a great day!