首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
Swoole Server 运行一段时间产生段错误
### 问题描述 Server 运行一段时间进程消失 产生段错误 Aug 22 02:30:08 VM_0_2_centos kernel: php[16674]: segfault at ce ip 00007f9710a52ef9 sp 00007f9704626360 error 4 in libc-2.17.so[7f9710a06000+1c2000] Aug 24 10:35:53 VM_0_2_centos kernel: php[17952]: segfault at 3 ip 00007fab29222ef9 sp 00007fab1cc26360 error 4 in libc-2.17.so[7fab291d6000+1c2000] Aug 24 19:24:56 VM_0_2_centos kernel: php[23387]: segfault at 14 ip 00007ff2d874eef9 sp 00007ff2cc226360 error 4 in libc-2.17.so[7ff2d8702000+1c2000] Sep 1 13:12:01 VM_0_2_centos kernel: php[13961]: segfault at 38 ip 00007f2575aceef9 sp 00007f2569626360 error 4 in libc-2.17.so[7f2575a82000+1c2000] Sep 3 00:57:57 VM_0_2_centos kernel: php[18798]: segfault at 1a4 ip 00007f5161398ef9 sp 00007f5154e26360 error 4 in libc-2.17.so[7f516134c000+1c2000] Sep 3 16:43:15 VM_0_2_centos kernel: php[458]: segfault at 6 ip 00007fc809570ef9 sp 00007fc7fd026360 error 4 in libc-2.17.so[7fc809524000+1c2000] ### Swoole版本,PHP版本,以及操作系统版本信息 PHP 7.2.24 (cli) (built: Aug 21 2020 12:11:30) ( NTS ) Copyright (c) 1997-2018 The PHP Group swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.16 Built => Aug 21 2020 14:07:06 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled pcre => enabled zlib => 1.2.7 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ### 相关代码 ```php 请将代码粘贴至此处(请勿用截图) $daemonize = $input->getOption('daemonize'); $container = new \Core\Containers(); $app = new \Slim\App($container->GetContainers()); if(env('APP_ENV') !== 'local'){ require __DIR__ . '/../routes.php'; } $port = (int) env('SW_HTTP_SERVER_PORT') ?: 8888; $http_server = new \Swoole\Http\Server('0.0.0.0', $port, SWOOLE_PROCESS, SWOOLE_SOCK_TCP); $http_server->set( [ 'daemonize' => $daemonize, //守护进程化 true/false 'pid_file' => $this->PidFile, 'reactor_num' => env('SW_REACTOR_NUM', 1), //reactor thread num 'worker_num' => env('SW_WORK_NUM', 8), //Swoole采用固定Worker进程的模式 'backlog' => 2048, //此参数将决定最多同时有多少个等待accept的连接。 'max_request' => env('SW_MAX_REQ', 3000), 'max_coroutine' => env('SW_MAX_COR', 30000), 'enable_coroutine' => true, 'dispatch_mode' => 1, // 1平均分配,2按FD取模固定分配,3抢占式分配,默认为取模(dispatch=2) 'log_level' => env('SW_LOG_LEVEL', 0), 'log_file' => __DIR__ . '/../logs/swoole.log', 'request_slowlog_file' => __DIR__ . '/../logs/trace.log', 'http_parse_post' => false, 'hook_flags' => [SWOOLE_HOOK_ALL, SWOOLE_HOOK_CURL], ] ); $http_server->on( 'WorkerStart', function ($serv, $worker_id) { } ); $http_server->on( 'start', function ($server) use ($port, $output, $daemonize) { $notice = "Slimxy Http Server is started at http://0.0.0.0:{$port}\n"; if ($daemonize) { $notice = "Slimxy Http Server is daemonize started at http://0.0.0.0:{$port}\n"; } $output->writeln("<success>{$notice}</success>"); } ); $http_server->on( 'request', function (Request $request, Response $response) use ($app) { if ($request->server['path_info'] == '/favicon.ico' || $request->server['request_uri'] == '/favicon.ico') { return $response->end(); } $slimRequest = \Slim\Http\Request::createFromEnvironment( new \Slim\Http\Environment( [ 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => $request->server['request_method']??"", 'REQUEST_URI' => $request->server['request_uri']??"", 'SERVER_PORT' => $request->server['server_port']??"", 'REQ_TIME_FLOAT' => $request->server['request_time_float']??"", 'HTTP_ACCEPT' => $request->header['accept']??"", 'HTTP_USER_AGENT' => $request->header['user-agent']??"", 'HTTP_HOST' => $request->header['host']??"", 'HTTP_CONTENT_TYPE' => $request->header['content-type']??"", ] ) ); if(env('APP_ENV') === 'local'){ require __DIR__ . '/../routes.php'; } $reqGet = $request->get??[]; $reqPost = $request->post??[]; //JSON if(!empty($request->rawContent())){ if(is_json($request->rawContent())){ $JsonArr = json_decode($request->rawContent(),true); if(!empty($JsonArr)){ $reqPost = array_merge($reqPost,$JsonArr); } } } $slimRequest->withMethod($request->server['request_method']); $slimRequest = $slimRequest->withQueryParams($reqGet); $slimRequest = $slimRequest->withParsedBody($reqPost); $processedResponse = $app->process($slimRequest, new \Slim\Http\Response()); // Set all the headers you will find in $processedResponse into swoole's $response foreach ($processedResponse->getHeaders() as $k => $v) { if (is_array($v)) { $response->header($k, $v[0]); } else { $response->header($k, $v); } } // Set the body return $response->end((string) $processedResponse->getBody()); } ); $http_server->start(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么?
发布于6年前 · 12 次浏览 · 来自
提问
Alonexy
### 问题描述 Server 运行一段时间进程消失 产生段错误 Aug 22 02:30:08 VM_0_2_centos kernel: php[16674]: segfault at ce ip 00007f9710a52ef9 sp 00007f9704626360 error 4 in libc-2.17.so[7f9710a06000+1c2000] Aug 24 10:35:53 VM_0_2_centos kernel: php[17952]: segfault at 3 ip 00007fab29222ef9 sp 00007fab1cc26360 error 4 in libc-2.17.so[7fab291d6000+1c2000] Aug 24 19:24:56 VM_0_2_centos kernel: php[23387]: segfault at 14 ip 00007ff2d874eef9 sp 00007ff2cc226360 error 4 in libc-2.17.so[7ff2d8702000+1c2000] Sep 1 13:12:01 VM_0_2_centos kernel: php[13961]: segfault at 38 ip 00007f2575aceef9 sp 00007f2569626360 error 4 in libc-2.17.so[7f2575a82000+1c2000] Sep 3 00:57:57 VM_0_2_centos kernel: php[18798]: segfault at 1a4 ip 00007f5161398ef9 sp 00007f5154e26360 error 4 in libc-2.17.so[7f516134c000+1c2000] Sep 3 16:43:15 VM_0_2_centos kernel: php[458]: segfault at 6 ip 00007fc809570ef9 sp 00007fc7fd026360 error 4 in libc-2.17.so[7fc809524000+1c2000] ### Swoole版本,PHP版本,以及操作系统版本信息 PHP 7.2.24 (cli) (built: Aug 21 2020 12:11:30) ( NTS ) Copyright (c) 1997-2018 The PHP Group swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.16 Built => Aug 21 2020 14:07:06 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled pcre => enabled zlib => 1.2.7 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ### 相关代码 ```php 请将代码粘贴至此处(请勿用截图) $daemonize = $input->getOption('daemonize'); $container = new \Core\Containers(); $app = new \Slim\App($container->GetContainers()); if(env('APP_ENV') !== 'local'){ require __DIR__ . '/../routes.php'; } $port = (int) env('SW_HTTP_SERVER_PORT') ?: 8888; $http_server = new \Swoole\Http\Server('0.0.0.0', $port, SWOOLE_PROCESS, SWOOLE_SOCK_TCP); $http_server->set( [ 'daemonize' => $daemonize, //守护进程化 true/false 'pid_file' => $this->PidFile, 'reactor_num' => env('SW_REACTOR_NUM', 1), //reactor thread num 'worker_num' => env('SW_WORK_NUM', 8), //Swoole采用固定Worker进程的模式 'backlog' => 2048, //此参数将决定最多同时有多少个等待accept的连接。 'max_request' => env('SW_MAX_REQ', 3000), 'max_coroutine' => env('SW_MAX_COR', 30000), 'enable_coroutine' => true, 'dispatch_mode' => 1, // 1平均分配,2按FD取模固定分配,3抢占式分配,默认为取模(dispatch=2) 'log_level' => env('SW_LOG_LEVEL', 0), 'log_file' => __DIR__ . '/../logs/swoole.log', 'request_slowlog_file' => __DIR__ . '/../logs/trace.log', 'http_parse_post' => false, 'hook_flags' => [SWOOLE_HOOK_ALL, SWOOLE_HOOK_CURL], ] ); $http_server->on( 'WorkerStart', function ($serv, $worker_id) { } ); $http_server->on( 'start', function ($server) use ($port, $output, $daemonize) { $notice = "Slimxy Http Server is started at http://0.0.0.0:{$port}\n"; if ($daemonize) { $notice = "Slimxy Http Server is daemonize started at http://0.0.0.0:{$port}\n"; } $output->writeln("<success>{$notice}</success>"); } ); $http_server->on( 'request', function (Request $request, Response $response) use ($app) { if ($request->server['path_info'] == '/favicon.ico' || $request->server['request_uri'] == '/favicon.ico') { return $response->end(); } $slimRequest = \Slim\Http\Request::createFromEnvironment( new \Slim\Http\Environment( [ 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => $request->server['request_method']??"", 'REQUEST_URI' => $request->server['request_uri']??"", 'SERVER_PORT' => $request->server['server_port']??"", 'REQ_TIME_FLOAT' => $request->server['request_time_float']??"", 'HTTP_ACCEPT' => $request->header['accept']??"", 'HTTP_USER_AGENT' => $request->header['user-agent']??"", 'HTTP_HOST' => $request->header['host']??"", 'HTTP_CONTENT_TYPE' => $request->header['content-type']??"", ] ) ); if(env('APP_ENV') === 'local'){ require __DIR__ . '/../routes.php'; } $reqGet = $request->get??[]; $reqPost = $request->post??[]; //JSON if(!empty($request->rawContent())){ if(is_json($request->rawContent())){ $JsonArr = json_decode($request->rawContent(),true); if(!empty($JsonArr)){ $reqPost = array_merge($reqPost,$JsonArr); } } } $slimRequest->withMethod($request->server['request_method']); $slimRequest = $slimRequest->withQueryParams($reqGet); $slimRequest = $slimRequest->withParsedBody($reqPost); $processedResponse = $app->process($slimRequest, new \Slim\Http\Response()); // Set all the headers you will find in $processedResponse into swoole's $response foreach ($processedResponse->getHeaders() as $k => $v) { if (is_array($v)) { $response->header($k, $v[0]); } else { $response->header($k, $v); } } // Set the body return $response->end((string) $processedResponse->getBody()); } ); $http_server->start(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么?
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-09-10
鲁飞
先测试最新版本是否可以复现core dump 如果复现参考文档向Swoole开发组提交日志 https://wiki.swoole.com/#/other/issue?id=%e5%85%b3%e4%ba%8e%e6%ae%b5%e9%94%99%e8%af%af%e6%a0%b8%e5%bf%83%e8%bd%ac%e5%82%a8
赞
0
回复
2020-09-10
Alonexy
回复
鲁飞
好 那我回头试一下最新的 这是这个版本的 ```shell GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /usr/local/php/bin/php...done. [New LWP 458] [New LWP 456] [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib64/libthread_db.so.1". Core was generated by `php Console http:server start -d'. Program terminated with signal 11, Segmentation fault. #0 0x00007fc809570ef9 in vfprintf () from /usr/lib64/libc.so.6 Missing separate debuginfos, use: debuginfo-install php72w-cli-7.2.31-2.w7.x86_64 (gdb) bt #0 0x00007fc809570ef9 in vfprintf () from /usr/lib64/libc.so.6 #1 0x00007fc80959bf39 in vsnprintf () from /usr/lib64/libc.so.6 #2 0x00007fc7ff121b20 in sw_snprintf (buf=0x7fc7f80008c0 "", size=16384, format=<optimized out>) at /tmp/pear/temp/swoole/src/core/base.c:897 #3 0x00007fc7ff156477 in swPort_onRead_http (reactor=0x7fc7feed9418, port=0x7fc7feed92e0, event=0x7fc7fd026ca0) at /tmp/pear/temp/swoole/src/server/port.cc:506 #4 0x00007fc7ff15994a in swReactorThread_onRead (reactor=<optimized out>, event=<optimized out>) at /tmp/pear/temp/swoole/src/server/reactor_thread.cc:668 #5 0x00007fc7ff14d394 in swReactorEpoll_wait (reactor=0x7fc7feed9418, timeo=<optimized out>) at /tmp/pear/temp/swoole/src/reactor/epoll.cc:257 #6 0x00007fc7ff15b2be in swReactorThread_loop (param=<optimized out>) at /tmp/pear/temp/swoole/src/server/reactor_thread.cc:1147 #7 0x00007fc808c86dd5 in start_thread () from /usr/lib64/libpthread.so.0 #8 0x00007fc809621ead in clone () from /usr/lib64/libc.so.6 ```
赞
0
回复
2020-09-10
Twosee
调高日志级别到SWOOLE_LOG_INFO 或 升级到最新版本 即可解决, 谢谢
赞
0
回复
2020-09-10
Alonexy
回复
Twosee
OK
赞
0
回复