Juniper / py-junos-eznc

Python library for Junos automation
https://www.juniper.net/documentation/en_US/junos-pyez/information-products/pathway-pages/junos-pyez-developer-guide.html
Apache License 2.0
668 stars 342 forks source link

Thread leak with PyEZ #1214

Open samta93 opened 1 year ago

samta93 commented 1 year ago

This simple script will results in thread leak in junos device.

from jnpr.junos import Device
import time

def get_server_detail():
    dev = Device(gather_facts=False)
    dev.open()
    dev.display_xml_rpc('show version', format='text')
    dev.close()

while True:
    get_server_detail()
    time.sleep(60)

Although we are closing the connection the thread count associated with the process will keep increasing after each sleep call.

samta93 commented 1 year ago

@vnitinv Can you please review this issue?

chidanandpujar commented 1 year ago

Hi ,

Monitored the script for few iterations thread count stands at 1 on off-box

from jnpr.junos import Device
import time

def get_server_detail():
    dev = Device(host='xx.xx.xx.xx', user='xyz', password='xyz', gather_facts=False)
    dev.open()
    dev.display_xml_rpc('show version', format='text')
    dev.close()

while True:
    get_server_detail()
    time.sleep(60)

Package               Version
--------------------- ------------------
bcrypt                4.0.1
cffi                  1.15.1
cryptography          38.0.3
Jinja2                3.1.2
junos-eznc            2.6.5+10.gc58107eb
lxml                  4.9.1
MarkupSafe            2.1.1
ncclient              0.6.13
netaddr               0.8.0
paramiko              2.12.0
pip                   21.1.3
pycparser             2.21
PyNaCl                1.5.0
pyparsing             3.0.9
pyserial              3.5
PyYAML                6.0
scp                   0.14.4
setuptools            56.0.0
six                   1.16.0
transitions           0.9.0
yamlordereddictloader 0.4.0

(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1
(venv) root@nms5:~/pyez_1213_thread_safety# cat /proc/13778/status | grep Threads
Threads:    1

Thanks & Regards Chidanand

chidanandpujar commented 1 year ago

following is the status of threads .

PID TID COMM TDNAME CPU PRI STATE WCHAN
12150 100212 cscript - -1 141 sleep select
12150 100325 cscript - -1 152 sleep usem
12150 100326 cscript - -1 129 sleep usem
12150 100327 cscript - -1 127 sleep usem
12150 100328 cscript - -1 127 sleep usem
12150 100329 cscript - -1 129 sleep usem
12150 100330 cscript - -1 129 sleep usem
12150 100331 cscript - -1 129 sleep usem
12150 100332 cscript - -1 129 sleep usem
12150 100333 cscript - -1 129 sleep usem
12150 100334 cscript - -1 129 sleep usem
12150 100335 cscript - -1 129 sleep usem
12150 100336 cscript - -1 129 sleep usem
12150 100337 cscript - -1 129 sleep usem
12150 100338 cscript - -1 129 sleep usem
12150 100339 cscript - -1 127 sleep usem
12150 100340 cscript - -1 129 sleep usem
12150 100341 cscript - -1 128 sleep usem
12150 100342 cscript - -1 129 sleep usem
12150 100343 cscript - -1 129 sleep usem
12150 100344 cscript - -1 127 sleep usem
12150 100345 cscript - -1 129 sleep usem
12150 100346 cscript - -1 129 sleep usem
12150 100347 cscript - -1 129 sleep usem
12150 100348 cscript - -1 129 sleep usem
12150 100349 cscript - -1 129 sleep usem
12150 100350 cscript - -1 129 sleep usem
12150 100351 cscript - -1 127 sleep usem
12150 100352 cscript - -1 129 sleep usem
12150 100353 cscript - -1 129 sleep usem
12150 100354 cscript - -1 129 sleep usem
12150 100355 cscript - -1 128 sleep usem
12150 100356 cscript - -1 129 sleep usem
12150 100357 cscript - -1 129 sleep usem
12150 100358 cscript - -1 129 sleep usem
12150 100359 cscript - -1 129 sleep usem
12150 100360 cscript - -1 129 sleep usem
12150 100361 cscript - -1 129 sleep usem
12150 100362 cscript - -1 129 sleep usem
12150 100363 cscript - -1 129 sleep usem

12150 100212 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_timedwait_sig _cv_timedwait_sig_sbt seltdwait kern_select sys_select swi_handler swi_exit 12150 100325 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100326 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100327 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100328 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100329 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100330 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100331 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100332 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100333 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100334 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100335 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100336 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100337 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100338 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100339 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100340 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100341 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100342 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100343 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100344 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100345 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100346 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100347 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100348 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100349 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100350 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100351 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100352 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100353 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100354 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100355 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100356 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100357 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100358 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100359 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100360 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100361 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100362 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit 12150 100363 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep umtx_op_sem2_wait swi_handler swi_exit 12150 100364 cscript - sched_switch mi_switch sleepq_catch_signals sleepq_wait_sig _sleep umtxq_sleep __umtx_op_sem2_wait swi_handler swi_exit

samta93 commented 1 year ago

@chidanandpujar did you find the root cause?