Skip to content

InvalidOperationException: Environment variable HOME not defined #3728

Description

@glindstr

Greetings,

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions