-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET Core 3 application cannot connect to database when deployed on a Docker image #3550
Comments
Similar problem. Seems like a thread wait is blocked on a semaphore from another (native?) thread that died perhaps. I had a call stack window open at one point, and by looking at my search history today:
Using sdk:3.0-alpine and aspnet:3.0-alpine instead of the default "3.0-buster" (Debian) got me past that. SQL has some issues with the "globalization invariant mode" on alpine, but that's solvable with: |
I put this in a generic/empty ASPNET CORE 3 harness (use the VS 2019 wizard) and added some stuff in Main to get a SqlConnection. This stripped down use case mimicked my initial encounter with this hanging connection issue, without me having migrated anything from CORE 2.2. Put a breakpoint on the _connect.Open() line, run in Docker, see that you hit the breakpoint, step into, wait a bit, press the debugger break button, see you're still on the _connect.Open() line, then open the call stack window.
|
I have the same problem, I'm using |
same issue here as well. Any new developments on this? |
Same issue, though the interesting point is:
|
@leecow @MichaelSimons any idea what's going on here? |
@scalablecory - based on @sageikosa repro, I'd suggest moving to/getting the SQL client team involved. The issue I am aware of is dotnet/SqlClient#222 but I am unaware of that causing a hang. |
@uncvrd we had the same issue and followed one of the answers in dotnet/SqlClient#222 and found a workaround. By adding these two lines to our dockerfile it successfully connected. Prior to adding these lines it was completely hanging on the sqlconnection .Open(). This seemed to be to a SQL 2014 instance specific issue for us as no issues with our SQL 2017 instances. RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf For example: FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS base |
@sep15ms we're currently running SQL 2017 so this probably won't fix things, but I'll report back after we try this in the office next week, thanks! |
FYI: my SQL server was a SQL2016 instance; and I didn't try with other version instances. |
@sep15ms thanks for the workaround, it has solved the issue for our .NET Core 3 application running in a Docker container |
The issue seems to be resolved, thank you @MichaelSimons for pointing out the issue. |
I am also facing kind of similar problem.My code is also stuck on db context and if i try to see it in quick watch it just break the application.Any other suggestion on it ? |
thanks. |
I still have the connection problem even with and this command
I am using a the standard aspnetcore3.1 image from the sample Does anyone know what is the issue? And here is the exception I'm getting
|
I am facing the same issue. Has anyone got this resolved? Please help! |
For those still dealing with this issue, we were able to overcome this problem by changing our image to Ubuntu Bionic. |
Thank you so, so much! I just spent the past 2 days running around in circles until I figured out that DbConnection.Open() was where the code was hanging (at first I thought i had certificate issues, ugh!). Using aspnet:3.1-buster-slim as base with a connection to SQL Server 2016, and the 2 lines fixed it! |
Hello, I hope you find this information usefull, thanks! |
I have a .Net Core 3.0 project that I've been trying to deploy to a docker container that cannot seem to connect to the database context ever since I upgraded from Core 2.2 to Core 3.0. I can run the project locally just fine, but when it's deployed to a Docker container, the app hangs at the first instance where I call my
context
, which happens to be in mymain()
method in myProgram.cs
:The app will hang indefinitely and never make it past the
context.Database.Migrate()
method. There isn't even a SQL Connection Timeout exception thrown, so it has to be something before it even tries to make the SQL connection. My docker container doesn't throw any errors either.Here's my dockerfile:
Any ideas as to why my app hangs indefinitely? Please let me know if there's any other files needed to debug. I figured the only thing necessary was the
dockerfile
because the whole project runs fine on my local machine. Thank you!The text was updated successfully, but these errors were encountered: