运行 ~24 小时后,Nginx 后面的 Flask/Python 应用程序出现 uWSGI 分段错误

问题描述 投票:0回答:0

问题

我有一个 Python/Flask 应用程序 在产品中运行,在 Nginx 后面使用 uWSGI,它通过 Docker 部署我的个人项目。当它突然开始

12-24 hours
时,它在大约
segfaulting
时非常有效。该应用程序接受请求并启动
Python thread
以通过 Docker 部署项目,因为这可能需要几分钟才能完成。然后我们立即通过该端点返回 200 以关闭请求连接,同时线程可以继续执行构建和部署。

我正在通过

Docker
运行Nginx应用程序(它接受请求并通过套接字将它们传递给uWSGI)。 uWSGI 和 Python 应用程序正在
bare-metal
上运行
M1 Mac mini
.

  • 蟒蛇:
    3.10
  • uWSGI:
    2.0.21
  • 烧瓶:
    2.*
  • 要求:
    2.*

预期结果

这个应用程序应该能够连续运行数周,而无需每天重新启动 uwsgi 的手动干预。段错误不应该发生。

尝试修复

我找到的唯一解决方案是完全重启 uwsgi。我已经尝试了数十种配置更改,包括超时、内存限制、在 X 次请求或时间后重新启动 worker,但没有什么可以正确地终止进程并在段错误后重新启动它,更不用说在它发生之前了。

项目配置

这是我的

uwsgi.ini
文件:

[uwsgi]
; uwsgi setup
master = true
auto-procname = true
procname-prefix = "harvey " ; space is important
strict = true
vacuum = true
die-on-term = true
need-app = true
single-interpreter = true
enable-threads = true

; stats
stats = /tmp/harvey.stats
memory-report = true

; app setup
uwsgi-socket = 127.0.0.1:5000
module = wsgi:APP

; workers
processes = 3
reload-on-rss = 22 ; this is almost certainly a hack, seems to segfault at anything over 22mb?

; daemonization
daemonize = $(HOME)/harvey/logs/uwsgi.log
log-maxsize = 1000000 ; 1mb

这是我的

nginx.conf
文件:

server {
    listen 80;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    location / {
        include uwsgi_params;
        # This uwsgi pass only works for Docker Desktop
        uwsgi_pass host.docker.internal:5000;
    }
}

段错误输出

!!! uWSGI process 76997 got Segmentation Fault !!!
*** backtrace of 76997 ***
0   uwsgi                               0x0000000102a2a09c uwsgi_backtrace + 52
1   uwsgi                               0x0000000102a2a5b0 uwsgi_segfault + 56
2   libsystem_platform.dylib            0x00000001843802a4 _sigtramp + 56
3   libdispatch.dylib                   0x00000001841df900 _dispatch_apply_with_attr_f + 1096
4   libdispatch.dylib                   0x00000001841dfb48 dispatch_apply + 108
5   CoreFoundation                      0x0000000184557eb4 __103-[CFPrefsSearchListSource synchronouslySendSystemMessage:andUserMessage:andDirectMessage:replyHandler:]_block_invoke.52 + 132
6   CoreFoundation                      0x00000001843e7a40 CFPREFERENCES_IS_WAITING_FOR_SYSTEM_AND_USER_CFPREFSDS + 100
7   CoreFoundation                      0x00000001845570e4 -[CFPrefsSearchListSource synchronouslySendSystemMessage:andUserMessage:andDirectMessage:replyHandler:] + 232
8   CoreFoundation                      0x00000001843e6160 -[CFPrefsSearchListSource alreadylocked_generationCountFromListOfSources:count:] + 232
9   CoreFoundation                      0x00000001843e5e6c -[CFPrefsSearchListSource alreadylocked_getDictionary:] + 468
10  CoreFoundation                      0x00000001843e59f0 -[CFPrefsSearchListSource alreadylocked_copyValueForKey:] + 172
11  CoreFoundation                      0x00000001843e5924 -[CFPrefsSource copyValueForKey:] + 52
12  CoreFoundation                      0x00000001843e58d8 __76-[_CFXPreferences copyAppValueForKey:identifier:container:configurationURL:]_block_invoke + 32
13  CoreFoundation                      0x00000001843ddf8c __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 376
14  CoreFoundation                      0x0000000184558764 -[_CFXPreferences withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 384
15  CoreFoundation                      0x00000001843dd860 -[_CFXPreferences copyAppValueForKey:identifier:container:configurationURL:] + 168
16  CoreFoundation                      0x00000001843dd77c _CFPreferencesCopyAppValueWithContainerAndConfiguration + 112
17  SystemConfiguration                 0x0000000184fab8ec SCDynamicStoreCopyProxiesWithOptions + 180
18  _scproxy.cpython-310-darwin.so      0x0000000103703aa0 get_proxies + 28
19  Python                              0x000000010301cba8 cfunction_vectorcall_NOARGS + 96
20  Python                              0x00000001030c4cf8 call_function + 128
21  Python                              0x00000001030c2538 _PyEval_EvalFrameDefault + 43144
22  Python                              0x00000001030b6a5c _PyEval_Vector + 376
23  Python                              0x00000001030c4cf8 call_function + 128
24  Python                              0x00000001030c2538 _PyEval_EvalFrameDefault + 43144
25  Python                              0x00000001030b6a5c _PyEval_Vector + 376
26  Python                              0x00000001030c4cf8 call_function + 128
27  Python                              0x00000001030c2538 _PyEval_EvalFrameDefault + 43144
28  Python                              0x00000001030b6a5c _PyEval_Vector + 376
29  Python                              0x0000000102fcaeac _PyObject_FastCallDictTstate + 96
30  Python                              0x0000000103040abc slot_tp_init + 196
31  Python                              0x0000000103038a8c type_call + 288
32  Python                              0x0000000102fcac44 _PyObject_MakeTpCall + 136
33  Python                              0x00000001030c4d88 call_function + 272
34  Python                              0x00000001030c2538 _PyEval_EvalFrameDefault + 43144
35  Python                              0x00000001030b6a5c _PyEval_Vector + 376
36  Python                              0x00000001030c4cf8 call_function + 128
37  Python                              0x00000001030c2538 _PyEval_EvalFrameDefault + 43144
38  Python                              0x00000001030b6a5c _PyEval_Vector + 376
39  Python                              0x00000001030c4cf8 call_function + 128
40  Python                              0x00000001030c25c0 _PyEval_EvalFrameDefault + 43280
41  Python                              0x00000001030b6a5c _PyEval_Vector + 376
42  Python                              0x0000000102fcdeb0 method_vectorcall + 124
43  Python                              0x00000001030c4cf8 call_function + 128
44  Python                              0x00000001030c25c0 _PyEval_EvalFrameDefault + 43280
45  Python                              0x00000001030b6a5c _PyEval_Vector + 376
46  Python                              0x0000000102fcdeb0 method_vectorcall + 124
47  Python                              0x00000001030c4cf8 call_function + 128
48  Python                              0x00000001030c25c0 _PyEval_EvalFrameDefault + 43280
49  Python                              0x00000001030b6a5c _PyEval_Vector + 376
50  Python                              0x0000000102fcdeb0 method_vectorcall + 124
51  Python                              0x00000001030c4cf8 call_function + 128
52  Python                              0x00000001030c25c0 _PyEval_EvalFrameDefault + 43280
53  Python                              0x00000001030b6a5c _PyEval_Vector + 376
54  Python                              0x0000000102fcdeb0 method_vectorcall + 124
55  Python                              0x00000001030c4cf8 call_function + 128
56  Python                              0x00000001030c25c0 _PyEval_EvalFrameDefault + 43280
57  Python                              0x00000001030b6a5c _PyEval_Vector + 376
58  Python                              0x0000000102fcdeb0 method_vectorcall + 124
59  Python                              0x00000001030c4cf8 call_function + 128
60  Python                              0x00000001030c25c0 _PyEval_EvalFrameDefault + 43280
61  Python                              0x00000001030b6a5c _PyEval_Vector + 376
62  Python                              0x00000001030c4cf8 call_function + 128
63  Python                              0x00000001030c2510 _PyEval_EvalFrameDefault + 43104
*** end of backtrace ***
python docker nginx segmentation-fault uwsgi
© www.soinside.com 2019 - 2024. All rights reserved.