question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InvalidOperationException: Environment variable HOME not defined

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
rojicommented, May 13, 2021

Not really… I guess I just assumed these environment variables are always present (which is almost always the case 😅).

Submitted #3730 to fix.

1reaction
czioutascommented, Jun 13, 2021

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: The environment variable HOME is not set. ...
Started Eclipse and got this error. How do I fix it? Warning: The environment variable HOME is not set. The following directory will...
Read more >
about Environment Variables - PowerShell
Describes how to access and manage environment variables in PowerShell. Environment variables store data that's used by the operating system ...
Read more >
The ConnectionString property has not been initialized. ...
I am encountering the following error when I debug my application. System.InvalidOperationException: The ConnectionString property has not ...
Read more >
Is the HOME environment variable normally set in Windows?
No. The equivalent environment variables that are set are HOMEDRIVE and HOMEPATH . Share.
Read more >
windows - What determines whether or not the %HOME% ...
On one Windows 10 PC, if I open a command prompt and echo the %HOME% environment variable, I get this result: C:\Users\johndoh>echo %home% ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found