wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.21k stars 295 forks source link

memory leak and dead lock #278

Closed beginning1126 closed 4 years ago

beginning1126 commented 6 years ago

hi, wandenberg first of all, thank you very much for your open source project. I am very lucky to encounter it Now, I have some problems. I hope you can help me. Thank you.

version: 0.5.1

1st problem: memory leak

function ngx_http_push_stream_output_filter, if ngx_http_output_filter return not NGX_OK, the parameter in will not call ngx_chain_update_chains, memory leak or not?

2st problem: dead lock

struct ngx_http_push_stream_shm_data_s, channels_mutex, only 10, all the channel share them, If a running channel use the same lock as the channel to be deleted, There will be a deadlock first lock--->channel->mutex second lock---->data->channels_trash_mutex Look at the following two process GDB stacks

(gdb) bt

0 0x0000003a3060d720 in sem_wait () from /lib64/libpthread.so.0

1 0x0000000000427975 in ngx_shmtx_lock (mtx=0x2b22d33292e0) at src/core/ngx_shmtx.c:110

2 0x00000000004d7849 in nxg_http_push_stream_free_channel_memory (data=0x2b22d3319000, force=0) at ../nginx-push-stream-module/src/ngx_http_push_stream_module_utils.c:1248

3 ngx_http_push_stream_free_memory_of_expired_channels (data=0x2b22d3319000, force=0) at ../nginx-push-stream-module/src/ngx_http_push_stream_module_utils.c:1229

4 ngx_http_push_stream_free_memory_of_expired_messages_and_channels_data (data=0x2b22d3319000, force=0) at ../nginx-push-stream-module/src/ngx_http_push_stream_module_utils.c:1338

5 0x00000000004dc1eb in ngx_http_push_stream_memory_cleanup (ev=) at ../nginx-push-stream-module/src/ngx_http_push_stream_module_utils.c:1274

6 ngx_http_push_stream_memory_cleanup_timer_wake_handler (ev=) at ../nginx-push-stream-module/src/ngx_http_push_stream_module_utils.c:1479

7 0x000000000043452b in ngx_event_expire_timers () at src/event/ngx_event_timer.c:94

8 0x000000000043434d in ngx_process_events_and_timers (cycle=0x21e4870) at src/event/ngx_event.c:262

9 0x000000000043b5e5 in ngx_worker_process_cycle (cycle=0x21e4870, data=) at src/os/unix/ngx_process_cycle.c:824

10 0x0000000000439c9c in ngx_spawn_process (cycle=0x21e4870, proc=0x43b4ea , data=0x4, name=0x51e4d3 "worker process", respawn=-3) at src/os/unix/ngx_process.c:198

11 0x000000000043a9bb in ngx_start_worker_processes (cycle=0x21e4870, n=14, type=-3) at src/os/unix/ngx_process_cycle.c:368

12 0x000000000043bc76 in ngx_master_process_cycle (cycle=0x21e4870) at src/os/unix/ngx_process_cycle.c:140

13 0x000000000041d42b in main (argc=, argv=) at src/core/nginx.c:408

========================================= (gdb) bt

0 0x0000003a3060d720 in sem_wait () from /lib64/libpthread.so.0

1 0x0000000000427975 in ngx_shmtx_lock (mtx=0x2b22d3319110) at src/core/ngx_shmtx.c:110

2 0x00000000004d407e in ngx_http_push_stream_throw_the_message_away (msg=0x2b23a73a3900, data=0x2b22d3319000) at ../nginx-push-stream-module/src/ngx_http_push_stream_module_utils.c:1391

3 0x00000000004d4220 in ngx_http_push_stream_ensure_qtd_of_messages (data=0x2b22d3319000, channel=0x2b233b083900, max_messages=6, expired=0)

at ../nginx-push-stream-module/src/ngx_http_push_stream_module_utils.c:84

4 0x00000000004d92a8 in ngx_http_push_stream_add_msg_to_channel (mcf=0x21e7aa0, log=0x2306bb0, channel=0x2b233b083900, text=, len=476, event_id=, event_type=0x0,

store_messages=1, temp_pool=0x239eaa0) at ../nginx-push-stream-module/src/ngx_http_push_stream_module_utils.c:440

5 0x00000000004decb5 in ngx_http_push_stream_publisher_body_handler (r=0x239eaf0) at ../nginx-push-stream-module/src/ngx_http_push_stream_module_publisher.c:271

6 0x000000000045a429 in ngx_http_read_client_request_body (r=0x239eaf0, post_handler=0x4deb1e ) at src/http/ngx_http_request_body.c:176

7 0x00000000004d59a1 in ngx_http_push_stream_publisher_handle_after_read_body (r=, post_handler=)

at ../nginx-push-stream-module/src/ngx_http_push_stream_module_publisher.c:147

8 0x00000000004df0ed in ngx_http_push_stream_publisher_handler (r=0x239eaf0) at ../nginx-push-stream-module/src/ngx_http_push_stream_module_publisher.c:122

9 0x000000000044c7fe in ngx_http_core_content_phase (r=0x239eaf0, ph=0x22708a0) at src/http/ngx_http_core_module.c:1407

10 0x0000000000447113 in ngx_http_core_run_phases (r=0x239eaf0) at src/http/ngx_http_core_module.c:888

11 0x0000000000447226 in ngx_http_handler (r=) at src/http/ngx_http_core_module.c:871

12 0x000000000044fe09 in ngx_http_process_request (r=0x239eaf0) at src/http/ngx_http_request.c:1902

13 0x00000000004525c4 in ngx_http_process_request_headers (rev=) at src/http/ngx_http_request.c:1333

14 0x0000000000452b63 in ngx_http_process_request_line (rev=0x2b2542139280) at src/http/ngx_http_request.c:1013

15 0x0000000000452e6e in ngx_http_keepalive_handler (rev=0x2b2542139280) at src/http/ngx_http_request.c:3183

16 0x000000000043cd97 in ngx_epoll_process_events (cycle=0x21e4870, timer=, flags=) at src/event/modules/ngx_epoll_module.c:685

17 0x00000000004342f3 in ngx_process_events_and_timers (cycle=0x21e4870) at src/event/ngx_event.c:248

18 0x000000000043b5e5 in ngx_worker_process_cycle (cycle=0x21e4870, data=) at src/os/unix/ngx_process_cycle.c:824

19 0x0000000000439c9c in ngx_spawn_process (cycle=0x21e4870, proc=0x43b4ea , data=0x1, name=0x51e4d3 "worker process", respawn=-3) at src/os/unix/ngx_process.c:198

20 0x000000000043a9bb in ngx_start_worker_processes (cycle=0x21e4870, n=14, type=-3) at src/os/unix/ngx_process_cycle.c:368

21 0x000000000043bc76 in ngx_master_process_cycle (cycle=0x21e4870) at src/os/unix/ngx_process_cycle.c:140

22 0x000000000041d42b in main (argc=, argv=) at src/core/nginx.c:408

thanks, best regard

wandenberg commented 6 years ago

hi @beginning1126

There is no memory leak on this case because Nginx works with a memory pool strategy, and in this situation, all the allocation is done in the memory pool of the request, once the connection is closed all the memory in this pool will be free, is how it works on the core implementation ;)

Regarding the dead lock this situation was fixed on version 0.5.2, please update to the latest version, you will have some bugs fixed and also make things easier in case you find any problem.

beginning1126 commented 6 years ago

hi wandenberg thank you for your reply, I will try version 0.5.2, thank you