运行约24小时后,Nginx后面的Flask/Python应用程序出现uWSGI分段故障

vybvopom  于 2023-03-29  发布在  Nginx
关注(0)|答案(1)|浏览(164)

问题

我有一个Python/Flask app运行在prod与uWSGI背后的Nginx,通过Docker部署我的个人项目.它的工作很好约12-24 hours时,它突然启动segfaulting .应用程序接受请求,并启动Python thread通过Docker部署一个项目,因为它可能需要几分钟的时间来做.然后,我们立即通过该端点返回200以关闭请求连接,同时线程可以继续执行构建和部署。
我通过Docker运行Nginx应用程序(它接受请求并通过套接字将其传递给uWSGI)。uWSGI和Python应用程序在M1 Mac mini上运行bare-metal

  • Python:Python
  • uWSGI:2.0.21
  • flask :2.*
  • 请求:2.*

预期结果

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

尝试修复

我发现的唯一解决方案是完全重启uwsgi.我已经尝试了几十个配置更改,包括超时,内存限制,在X次请求或时间后重启workers,没有什么可以正确地杀死进程并在segfault后重新启动它,更不用说在它发生之前了。

项目配置

下面是我的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;
    }
}

Segfault输出

!!! 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 ***
vptzau2j

vptzau2j1#

我能够找到问题的解决方案,它似乎是特定于macOS,这是我运行uwsgi的地方。根据https://bugs.python.org/issue30385https://github.com/unbit/uwsgi/issues/1722,建议将os.environ["no_proxy"] = "*"添加到应用程序中。这消除了对macOS CFPREFERENCES的依赖,这最终导致了segfault。这可能不是一个完美的解决方案;然而,它是为我的用例工作.该应用程序已经运行了5天现在不间断时,以前它不能使它24小时没有segfaulting这表明承诺,我不需要一个代理.

相关问题