{"action":"created","issue":{"url":"https://api.github.com/repos/swoole/swoole-src/issues/2123","repository_url":"https://api.github.com/repos/swoole/swoole-src","labels_url":"https://api.github.com/repos/swoole/swoole-src/issues/2123/labels{/name}","comments_url":"https://api.github.com/repos/swoole/swoole-src/issues/2123/comments","events_url":"https://api.github.com/repos/swoole/swoole-src/issues/2123/events","html_url":"https://github.com/swoole/swoole-src/issues/2123","id":381452804,"node_id":"MDU6SXNzdWUzODE0NTI4MDQ=","number":2123,"title":"疑似内存泄漏问题","user":{"login":"Yurunsoft","id":20104656,"node_id":"MDQ6VXNlcjIwMTA0NjU2","avatar_url":"https://avatars2.githubusercontent.com/u/20104656?v=4","gravatar_id":"","url":"https://api.github.com/users/Yurunsoft","html_url":"https://github.com/Yurunsoft","followers_url":"https://api.github.com/users/Yurunsoft/followers","following_url":"https://api.github.com/users/Yurunsoft/following{/other_user}","gists_url":"https://api.github.com/users/Yurunsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Yurunsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yurunsoft/subscriptions","organizations_url":"https://api.github.com/users/Yurunsoft/orgs","repos_url":"https://api.github.com/users/Yurunsoft/repos","events_url":"https://api.github.com/users/Yurunsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Yurunsoft/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-11-16T05:31:09Z","updated_at":"2018-11-16T10:36:22Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"发现处理请求后，RES内存占用一直在涨\r\n\r\nPHP: 7.1.23\r\nSwoole: 4.2.7\r\n\r\n代码：\r\n```php\r\n<?php\r\n$http = new Swoole\\Http\\Server(\"127.0.0.1\", 9501);\r\n$http->set([\r\n    'worker_num'    =>  1,\r\n]);\r\n$http->on('request', function ($request, $response) {\r\n    $response->end(\"<h1>Hello Swoole. #\".rand(1000, 9999).\"</h1>\");\r\n});\r\n$http->start();\r\n```\r\n压测代码：\r\n`ab -n 1000 -c 100 http://127.0.0.1:9501/`\r\nvalgrind 日志：\r\n```\r\n==15596== Memcheck, a memory error detector\r\n==15596== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.\r\n==15596== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info\r\n==15596== Command: php ../../imi/test2.php\r\n==15596==\r\n==15596== error calling PR_SET_PTRACER, vgdb might block\r\n^C==15596==\r\n==15596== Process terminating with default action of signal 2 (SIGINT)\r\n==15599==\r\n==15599== Process terminating with default action of signal 2 (SIGINT)\r\n==15597==\r\n==15597== Process terminating with default action of signal 2 (SIGINT)\r\n==15596==    at 0x64C4767: kill (syscall-template.S:84)\r\n==15599==    at 0x64C4767: kill (syscall-template.S:84)\r\n==15596==    by 0x39E113: ??? (in /usr/bin/php7.1)\r\n==15597==    at 0x64C4767: kill (syscall-template.S:84)\r\n==15599==    by 0x39E113: ??? (in /usr/bin/php7.1)\r\n==15596==    by 0x39E211: zend_signal_handler_defer (in /usr/bin/php7.1)\r\n==15597==    by 0x39E113: ??? (in /usr/bin/php7.1)\r\n==15599==    by 0x39E211: zend_signal_handler_defer (in /usr/bin/php7.1)\r\n==15596==    by 0x64C44AF: ??? (in /lib/x86_64-linux-gnu/libc-2.23.so)\r\n==15597==    by 0x39E211: zend_signal_handler_defer (in /usr/bin/php7.1)\r\n==15599==    by 0x64C44AF: ??? (in /lib/x86_64-linux-gnu/libc-2.23.so)\r\n==15596==    by 0x6596A12: ??? (syscall-template.S:84)\r\n==15597==    by 0x64C44AF: ??? (in /lib/x86_64-linux-gnu/libc-2.23.so)\r\n==15599==    by 0x65969F2: __epoll_wait_nocancel (syscall-template.S:84)\r\n==15596==    by 0x9871C47: swReactorEpoll_wait (epoll.c:226)\r\n==15596==    by 0x986142D: swServer_start_proxy (server.c:416)\r\n==15597==    by 0x6869E8F: wait (wait.c:29)\r\n==15599==    by 0x9871C47: swReactorEpoll_wait (epoll.c:226)\r\n==15596==    by 0x986142D: swServer_start (server.c:781)\r\n==15597==    by 0x98559C1: swManager_loop (manager.c:263)\r\n==15599==    by 0x9866792: swWorker_loop (worker.c:792)\r\n==15596==    by 0x98E0A12: zim_swoole_server_start (swoole_server.c:2848)\r\n==15597==    by 0x98559C1: swManager_start (manager.c:176)\r\n==15599==    by 0x9854F2E: swManager_spawn_worker (manager.c:508)\r\n==15596==    by 0x414B0F: ??? (in /usr/bin/php7.1)\r\n==15597==    by 0x984C73C: swFactoryProcess_start (process.c:86)\r\n==15599==    by 0x985568D: swManager_start (manager.c:144)\r\n==15596==    by 0x3BB85A: execute_ex (in /usr/bin/php7.1)\r\n==15597==    by 0x986102A: swServer_start (server.c:762)\r\n==15599==    by 0x984C73C: swFactoryProcess_start (process.c:86)\r\n==15596==    by 0x416ADF: zend_execute (in /usr/bin/php7.1)\r\n==15597==    by 0x98E0A12: zim_swoole_server_start (swoole_server.c:2848)\r\n==15599==    by 0x986102A: swServer_start (server.c:762)\r\n==15596==    by 0x371B52: zend_execute_scripts (in /usr/bin/php7.1)\r\n==15597==    by 0x414B0F: ??? (in /usr/bin/php7.1)\r\n==15599==    by 0x98E0A12: zim_swoole_server_start (swoole_server.c:2848)\r\n==15597==    by 0x3BB85A: execute_ex (in /usr/bin/php7.1)\r\n==15597==    by 0x416ADF: zend_execute (in /usr/bin/php7.1)\r\n==15596==\r\n==15596== HEAP SUMMARY:\r\n==15596==     in use at exit: 4,841,167 bytes in 26,106 blocks\r\n==15596==   total heap usage: 33,214 allocs, 7,108 frees, 5,647,011 bytes allocated\r\n==15596==\r\n==15597==\r\n==15599==\r\n==15597== HEAP SUMMARY:\r\n==15597==     in use at exit: 4,045,247 bytes in 26,080 blocks\r\n==15597==   total heap usage: 33,188 allocs, 7,108 frees, 4,851,091 bytes allocated\r\n==15597==\r\n==15599== HEAP SUMMARY:\r\n==15599==     in use at exit: 4,472,103 bytes in 26,089 blocks\r\n==15599==   total heap usage: 33,197 allocs, 7,108 frees, 5,277,947 bytes allocated\r\n==15599==\r\n==15599== LEAK SUMMARY:\r\n==15599==    definitely lost: 0 bytes in 0 blocks\r\n==15599==    indirectly lost: 0 bytes in 0 blocks\r\n==15599==      possibly lost: 1,629,064 bytes in 16,810 blocks\r\n==15599==    still reachable: 2,843,039 bytes in 9,279 blocks\r\n==15599==         suppressed: 0 bytes in 0 blocks\r\n==15599== Rerun with --leak-check=full to see details of leaked memory\r\n==15599==\r\n==15599== For counts of detected and suppressed errors, rerun with: -v\r\n==15599== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)\r\n==15597== LEAK SUMMARY:\r\n==15597==    definitely lost: 0 bytes in 0 blocks\r\n==15597==    indirectly lost: 0 bytes in 0 blocks\r\n==15597==      possibly lost: 1,629,064 bytes in 16,810 blocks\r\n==15597==    still reachable: 2,416,183 bytes in 9,270 blocks\r\n==15597==         suppressed: 0 bytes in 0 blocks\r\n==15597== Rerun with --leak-check=full to see details of leaked memory\r\n==15597==\r\n==15597== For counts of detected and suppressed errors, rerun with: -v\r\n==15597== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)\r\n==15596== LEAK SUMMARY:\r\n==15596==    definitely lost: 0 bytes in 0 blocks\r\n==15596==    indirectly lost: 0 bytes in 0 blocks\r\n==15596==      possibly lost: 1,694,904 bytes in 16,813 blocks\r\n==15596==    still reachable: 3,146,263 bytes in 9,293 blocks\r\n==15596==         suppressed: 0 bytes in 0 blocks\r\n==15596== Rerun with --leak-check=full to see details of leaked memory\r\n==15596==\r\n==15596== For counts of detected and suppressed errors, rerun with: -v\r\n==15596== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)\r\nKilled\r\nroot@Yurun:/mnt/d/projects/xincheng-api-swoole/src# USE_ZEND_ALLOC=0 valgrind php ../../imi/test2\r\n.php\r\n==15600== Memcheck, a memory error detector\r\n==15600== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.\r\n==15600== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info\r\n==15600== Command: php ../../imi/test2.php\r\n==15600==\r\n==15600== error calling PR_SET_PTRACER, vgdb might block\r\n==15600== Thread 2:\r\n==15600== Syscall param write(buf) points to uninitialised byte(s)\r\n==15600==    at 0x68694BD: ??? (syscall-template.S:84)\r\n==15600==    by 0x94D7212: swReactorThread_send2worker (reactor_thread.c:557)\r\n==15600==    by 0x94D8D7E: swReactorThread_dispatch (reactor_thread.c:1484)\r\n==15600==    by 0x94D19D3: swPort_onRead_http (port.c:451)\r\n==15600==    by 0x94D6211: swReactorThread_onRead (reactor_thread.c:956)\r\n==15600==    by 0x94ECDF8: swReactorEpoll_wait (epoll.c:258)\r\n==15600==    by 0x94D8693: swReactorThread_loop (reactor_thread.c:1370)\r\n==15600==    by 0x68606B9: start_thread (pthread_create.c:333)\r\n==15600==    by 0x659641C: clone (clone.S:109)\r\n==15600==  Address 0x1998dc91 is on thread 2's stack\r\n==15600==  in frame #2, created by swReactorThread_dispatch (reactor_thread.c:1383)\r\n==15600==\r\n==15603== error calling PR_SET_PTRACER, vgdb might block\r\n==15603== Syscall param socketcall.sendto(msg) points to uninitialised byte(s)\r\n==15603==    at 0x686999D: send (send.c:26)\r\n==15603==    by 0x94EC15B: swConnection_send (connection.h:211)\r\n==15603==    by 0x94EC15B: swReactor_write (base.c:272)\r\n==15603==    by 0x94C7CA5: swFactoryProcess_finish (process.c:280)\r\n==15603==    by 0x94D91FA: swServer_tcp_send (server.c:1065)\r\n==15603==    by 0x951AC56: zim_swoole_http_response_end (swoole_http_server.c:2095)\r\n==15603==    by 0x414B0F: ??? (in /usr/bin/php7.1)\r\n==15603==    by 0x3BB85A: execute_ex (in /usr/bin/php7.1)\r\n==15603==    by 0x950380D: sw_coro_func(void*) (swoole_coroutine.cc:255)\r\n==15603==    by 0x94BFA6A: swoole::Context::context_func(void*) (context.cc:82)\r\n==15603==    by 0x9576A10: make_fcontext (make_x86_64_sysv_elf_gas.S:64)\r\n==15603==  Address 0x1938fe69 is 2,088,489 bytes inside a block of size 2,097,152 alloc'd\r\n==15603==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==15603==    by 0x94BF7BF: swoole::Context::Context(unsigned long, void (*)(void*), void*) (context.cc:31)\r\n==15603==    by 0x94BE1C7: coroutine_s (base.cc:37)\r\n==15603==    by 0x94BE1C7: coroutine_create (base.cc:143)\r\n==15603==    by 0x9503F83: sw_coro_create (swoole_coroutine.cc:297)\r\n==15603==    by 0x9518E1D: php_swoole_http_onReceive (swoole_http_server.c:1166)\r\n==15603==    by 0x94E0EF3: swWorker_onTask (worker.c:309)\r\n==15603==    by 0x94E12C8: swWorker_onPipeReceive (worker.c:834)\r\n==15603==    by 0x94ECDF8: swReactorEpoll_wait (epoll.c:258)\r\n==15603==    by 0x94E1792: swWorker_loop (worker.c:792)\r\n==15603==    by 0x94CFF2E: swManager_spawn_worker (manager.c:508)\r\n==15603==    by 0x94D068D: swManager_start (manager.c:144)\r\n==15603==    by 0x94C773C: swFactoryProcess_start (process.c:86)\r\n==15603==\r\n==15603== Syscall param socketcall.sendto(msg) points to uninitialised byte(s)\r\n==15603==    at 0x686999D: send (send.c:26)\r\n==15603==    by 0x94EC15B: swConnection_send (connection.h:211)\r\n==15603==    by 0x94EC15B: swReactor_write (base.c:272)\r\n==15603==    by 0x94C7CA5: swFactoryProcess_finish (process.c:280)\r\n==15603==    by 0x94C8566: swFactoryProcess_end (process.c:339)\r\n==15603==    by 0x94DA244: swServer_tcp_close (server.c:1195)\r\n==15603==    by 0x951AD1F: zim_swoole_http_response_end (swoole_http_server.c:2114)\r\n==15603==    by 0x414B0F: ??? (in /usr/bin/php7.1)\r\n==15603==    by 0x3BB85A: execute_ex (in /usr/bin/php7.1)\r\n==15603==    by 0x950380D: sw_coro_func(void*) (swoole_coroutine.cc:255)\r\n==15603==    by 0x94BFA6A: swoole::Context::context_func(void*) (context.cc:82)\r\n==15603==    by 0x9576A10: make_fcontext (make_x86_64_sysv_elf_gas.S:64)\r\n==15603==  Address 0x1938fe19 is 2,088,409 bytes inside a block of size 2,097,152 alloc'd\r\n==15603==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==15603==    by 0x94BF7BF: swoole::Context::Context(unsigned long, void (*)(void*), void*) (context.cc:31)\r\n==15603==    by 0x94BE1C7: coroutine_s (base.cc:37)\r\n==15603==    by 0x94BE1C7: coroutine_create (base.cc:143)\r\n==15603==    by 0x9503F83: sw_coro_create (swoole_coroutine.cc:297)\r\n==15603==    by 0x9518E1D: php_swoole_http_onReceive (swoole_http_server.c:1166)\r\n==15603==    by 0x94E0EF3: swWorker_onTask (worker.c:309)\r\n==15603==    by 0x94E12C8: swWorker_onPipeReceive (worker.c:834)\r\n==15603==    by 0x94ECDF8: swReactorEpoll_wait (epoll.c:258)\r\n==15603==    by 0x94E1792: swWorker_loop (worker.c:792)\r\n==15603==    by 0x94CFF2E: swManager_spawn_worker (manager.c:508)\r\n==15603==    by 0x94D068D: swManager_start (manager.c:144)\r\n==15603==    by 0x94C773C: swFactoryProcess_start (process.c:86)\r\n==15603==\r\n^C==15600==\r\n==15600== Process terminating with default action of signal 2 (SIGINT)\r\n==15603==\r\n==15603== Process terminating with default action of signal 2 (SIGINT)\r\n==15601==\r\n==15601== Process terminating with default action of signal 2 (SIGINT)\r\n==15600==    at 0x64C4767: kill (syscall-template.S:84)\r\n==15603==    at 0x64C4767: kill (syscall-template.S:84)\r\n==15600==    by 0x39E113: ??? (in /usr/bin/php7.1)\r\n==15601==    at 0x64C4767: kill (syscall-template.S:84)\r\n==15603==    by 0x39E113: ??? (in /usr/bin/php7.1)\r\n==15600==    by 0x39E211: zend_signal_handler_defer (in /usr/bin/php7.1)\r\n==15601==    by 0x39E113: ??? (in /usr/bin/php7.1)\r\n==15603==    by 0x39E211: zend_signal_handler_defer (in /usr/bin/php7.1)\r\n==15600==    by 0x64C44AF: ??? (in /lib/x86_64-linux-gnu/libc-2.23.so)\r\n==15601==    by 0x39E211: zend_signal_handler_defer (in /usr/bin/php7.1)\r\n==15603==    by 0x64C44AF: ??? (in /lib/x86_64-linux-gnu/libc-2.23.so)\r\n==15600==    by 0x6596A12: ??? (syscall-template.S:84)\r\n==15601==    by 0x64C44AF: ??? (in /lib/x86_64-linux-gnu/libc-2.23.so)\r\n==15603==    by 0x65969F2: __epoll_wait_nocancel (syscall-template.S:84)\r\n==15600==    by 0x94ECC47: swReactorEpoll_wait (epoll.c:226)\r\n==15603==    by 0x94ECC47: swReactorEpoll_wait (epoll.c:226)\r\n==15600==    by 0x94DC42D: swServer_start_proxy (server.c:416)\r\n==15601==    by 0x6869E8F: wait (wait.c:29)\r\n==15603==    by 0x94E1792: swWorker_loop (worker.c:792)\r\n==15600==    by 0x94DC42D: swServer_start (server.c:781)\r\n==15603==    by 0x94CFF2E: swManager_spawn_worker (manager.c:508)\r\n==15601==    by 0x94D09C1: swManager_loop (manager.c:263)\r\n==15600==    by 0x955BA12: zim_swoole_server_start (swoole_server.c:2848)\r\n==15603==    by 0x94D068D: swManager_start (manager.c:144)\r\n==15601==    by 0x94D09C1: swManager_start (manager.c:176)\r\n==15600==    by 0x414B0F: ??? (in /usr/bin/php7.1)\r\n==15603==    by 0x94C773C: swFactoryProcess_start (process.c:86)\r\n==15601==    by 0x94C773C: swFactoryProcess_start (process.c:86)\r\n==15600==    by 0x3BB85A: execute_ex (in /usr/bin/php7.1)\r\n==15603==    by 0x94DC02A: swServer_start (server.c:762)\r\n==15601==    by 0x94DC02A: swServer_start (server.c:762)\r\n==15600==    by 0x416ADF: zend_execute (in /usr/bin/php7.1)\r\n==15603==    by 0x955BA12: zim_swoole_server_start (swoole_server.c:2848)\r\n==15601==    by 0x955BA12: zim_swoole_server_start (swoole_server.c:2848)\r\n==15600==    by 0x371B52: zend_execute_scripts (in /usr/bin/php7.1)\r\n==15601==    by 0x414B0F: ??? (in /usr/bin/php7.1)\r\n==15601==    by 0x3BB85A: execute_ex (in /usr/bin/php7.1)\r\n==15601==    by 0x416ADF: zend_execute (in /usr/bin/php7.1)\r\n==15600==\r\n==15603==\r\n==15600== HEAP SUMMARY:\r\n==15600==     in use at exit: 5,196,694 bytes in 26,279 blocks\r\n==15600==   total heap usage: 36,847 allocs, 10,568 frees, 71,669,843 bytes allocated\r\n==15600==\r\n==15603== HEAP SUMMARY:\r\n==15603==     in use at exit: 4,827,630 bytes in 26,262 blocks\r\n==15603==   total heap usage: 88,835 allocs, 62,573 frees, 2,369,155,979 bytes allocated\r\n==15603==\r\n==15601==\r\n==15601== HEAP SUMMARY:\r\n==15601==     in use at exit: 4,400,774 bytes in 26,253 blocks\r\n==15601==   total heap usage: 33,821 allocs, 7,568 frees, 5,273,923 bytes allocated\r\n==15601==\r\n==15603== LEAK SUMMARY:\r\n==15603==    definitely lost: 40 bytes in 1 blocks\r\n==15603==    indirectly lost: 0 bytes in 0 blocks\r\n==15603==      possibly lost: 1,643,026 bytes in 16,929 blocks\r\n==15603==    still reachable: 3,184,564 bytes in 9,332 blocks\r\n==15603==         suppressed: 0 bytes in 0 blocks\r\n==15603== Rerun with --leak-check=full to see details of leaked memory\r\n==15603==\r\n==15603== For counts of detected and suppressed errors, rerun with: -v\r\n==15603== Use --track-origins=yes to see where uninitialised values come from\r\n==15603== ERROR SUMMARY: 2000 errors from 2 contexts (suppressed: 0 from 0)\r\n==15601== LEAK SUMMARY:\r\n==15601==    definitely lost: 40 bytes in 1 blocks\r\n==15601==    indirectly lost: 0 bytes in 0 blocks\r\n==15601==      possibly lost: 1,643,122 bytes in 16,930 blocks\r\n==15601==    still reachable: 2,757,612 bytes in 9,322 blocks\r\n==15601==         suppressed: 0 bytes in 0 blocks\r\n==15601== Rerun with --leak-check=full to see details of leaked memory\r\n==15601==\r\n==15601== For counts of detected and suppressed errors, rerun with: -v\r\n==15601== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)\r\n==15600== LEAK SUMMARY:\r\n==15600==    definitely lost: 40 bytes in 1 blocks\r\n==15600==    indirectly lost: 0 bytes in 0 blocks\r\n==15600==      possibly lost: 1,708,962 bytes in 16,933 blocks\r\n==15600==    still reachable: 3,487,692 bytes in 9,345 blocks\r\n==15600==         suppressed: 0 bytes in 0 blocks\r\n==15600== Rerun with --leak-check=full to see details of leaked memory\r\n==15600==\r\n==15600== For counts of detected and suppressed errors, rerun with: -v\r\n==15600== Use --track-origins=yes to see where uninitialised values come from\r\n==15600== ERROR SUMMARY: 1000 errors from 1 contexts (suppressed: 0 from 0)\r\nKilled\r\n```"},"comment":{"url":"https://api.github.com/repos/swoole/swoole-src/issues/comments/439352848","html_url":"https://github.com/swoole/swoole-src/issues/2123#issuecomment-439352848","issue_url":"https://api.github.com/repos/swoole/swoole-src/issues/2123","id":439352848,"node_id":"MDEyOklzc3VlQ29tbWVudDQzOTM1Mjg0OA==","user":{"login":"flddr","id":42785945,"node_id":"MDQ6VXNlcjQyNzg1OTQ1","avatar_url":"https://avatars2.githubusercontent.com/u/42785945?v=4","gravatar_id":"","url":"https://api.github.com/users/flddr","html_url":"https://github.com/flddr","followers_url":"https://api.github.com/users/flddr/followers","following_url":"https://api.github.com/users/flddr/following{/other_user}","gists_url":"https://api.github.com/users/flddr/gists{/gist_id}","starred_url":"https://api.github.com/users/flddr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flddr/subscriptions","organizations_url":"https://api.github.com/users/flddr/orgs","repos_url":"https://api.github.com/users/flddr/repos","events_url":"https://api.github.com/users/flddr/events{/privacy}","received_events_url":"https://api.github.com/users/flddr/received_events","type":"User","site_admin":false},"created_at":"2018-11-16T10:36:22Z","updated_at":"2018-11-16T10:36:22Z","author_association":"NONE","body":"Are you doing `ab -n 1000 -c 100 http://127.0.0.1:9501/` and `CTRL+C` to `test2.php`?"}}
{"actor":{"display_login":"flddr"}}