【问题标题】:.net core docker container exited with error code 139 in production because of Null Exception由于 Null 异常,.net core docker 容器在生产中退出并出现错误代码 139
【发布时间】:2020-05-11 16:52:10
【问题描述】:

我有一个带有 .net 核心网络应用程序的 docker 容器。 docker 已退出,错误代码为 139。 Docker 检查没有 oom 指示
当我查看日志时,我看到了这一点,没有更多提示:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Services.Web.Services.ProductClient.RunCient.<>c__DisplayClass5_0.<<ScrapeProfileInfo>b__0>d.MoveNext() in /src/Services.Web/Services/Clients/ProductClient.cs:line 30
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
   at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

ProductClient.cs: line 30 中没有潜在的空异常风险... if (txt == string.Empty) return;

  1. 什么可能导致这个异常,这条线完全没有风险?
  2. Docker 不会因为一个异常而存在,它是否暗示了可能发生的事情?

我托管在 Google 云平台上。 docker 位于计算引擎下的 ubuntu 服务器上...(docker-compose)

更新
构建是 docker build
RUN dotnet build "TestServices.Web.csproj" -c Release -o /app/build
不使用 c# 可为空的特性

谢谢

【问题讨论】:

  • 你的代码是在调试还是发布模式下编译的?你在使用可空值吗?你能提供更多代码的概述吗?

标签: c# docker exit-code


【解决方案1】:

我不认为问题出在 docker 上,更可能出在 c# 中

你可以尝试的事情:

  1. 将构建模式更改为调试:-c Debug。优化期间的 C# 编译器可以内联某些函数,并且 NPE 可能来自与异常状态不同的行(请参阅https://developer.azurewebsites.net/2015/11/net-c-build-release-mode-with-full-stack-trace-and-line-numbers/
  2. 使用可为空值。它对跟踪潜在的 NPE 问题有很大帮助。
  3. 之前尝试检查空值。添加一个测试子句if (txt is null),看看你是否确定那里的txt不为null。

【讨论】:

  • 我会尝试一下,大约 2,NPE 不会被扔在那里。即使 txt 为空,也不应抛出 NPE。我会更新。谢谢
猜你喜欢
  • 2019-04-07
  • 2021-03-07
  • 2019-08-25
  • 1970-01-01
  • 2017-01-20
  • 1970-01-01
  • 2016-09-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多