jupyter_server
                                
                                 jupyter_server copied to clipboard
                                
                                    jupyter_server copied to clipboard
                            
                            
                            
                        Leaking file descriptor from jupyter server
Description
I am writing a python client that executes jupyter notebook. I notice that after each start and stop kernel the sockets (file descriptors) are being leaked which eventually leads to "too many files open error" in the jupyter server.
Starting jupyter server
jupyter server --log-level=DEBUG
Starting a python kernel
curl -X POST "http://localhost:8888/api/kernels"
Then stopping the kernel
curl -X DELETE "http://localhost:8888/api/kernels/<kernel_id>"
Using lsof to list open files lsof -p <p_id> | wc -l
After each start and stop kernel action, output of lsof -p <p_id | wc -l increases by 8.
python3.7 59227 mac-user   46u    unix 0x51b57e97e7cf0d5d        0t0            ->0x51b57e97e7cf15f5
python3.7 59227 mac-user   47u    unix 0x51b57e97e7cf15f5        0t0            ->0x51b57e97e7cf0d5d
python3.7 59227 mac-user   48u    unix 0x51b57e97e7cf2595        0t0            ->0x51b57e97e7cf2725
python3.7 59227 mac-user   49u    unix 0x51b57e97e7cf2725        0t0            ->0x51b57e97e7cf2595
python3.7 59227 mac-user   50u  KQUEUE                                          count=0, state=0xa
python3.7 59227 mac-user   51u    unix 0x51b57e97e7cf0eed        0t0            ->0x51b57e97e7cf2e2d
python3.7 59227 mac-user   52u    unix 0x51b57e97e7cf2e2d        0t0            ->0x51b57e97e7cf0eed
python3.7 59227 mac-user   53u  KQUEUE                                          count=0, state=0xa
(jupyter_server) f01898783380$ conda list
# packages in environment at /Users/npalania/opt/miniconda2/envs/jupyter_server:
#
# Name                    Version                   Build  Channel
appnope                   0.1.0                    pypi_0    pypi
attrs                     19.3.0                   pypi_0    pypi
backcall                  0.1.0                    pypi_0    pypi
bleach                    3.1.5                    pypi_0    pypi
ca-certificates           2020.1.1                      0  
certifi                   2020.4.5.1               py37_0  
decorator                 4.4.2                    pypi_0    pypi
defusedxml                0.6.0                    pypi_0    pypi
entrypoints               0.3                      pypi_0    pypi
importlib-metadata        1.6.0                    pypi_0    pypi
ipykernel                 5.3.0                    pypi_0    pypi
ipython                   7.14.0                   pypi_0    pypi
ipython-genutils          0.2.0                    pypi_0    pypi
jedi                      0.17.0                   pypi_0    pypi
jinja2                    2.11.2                   pypi_0    pypi
jsonschema                3.2.0                    pypi_0    pypi
jupyter-client            6.1.3                    pypi_0    pypi
jupyter-core              4.6.3                    pypi_0    pypi
jupyter-server            0.3.0                     dev_0    <develop>
libcxx                    10.0.0                        1  
libedit                   3.1.20181209         hb402a30_0  
libffi                    3.3                  h0a44026_1  
markupsafe                1.1.1                    pypi_0    pypi
mistune                   0.8.4                    pypi_0    pypi
nbconvert                 5.6.1                    pypi_0    pypi
nbformat                  5.0.6                    pypi_0    pypi
ncurses                   6.2                  h0a44026_1  
notebook                  6.0.3                    pypi_0    pypi
openssl                   1.1.1g               h1de35cc_0  
packaging                 20.4                     pypi_0    pypi
pandocfilters             1.4.2                    pypi_0    pypi
parso                     0.7.0                    pypi_0    pypi
pexpect                   4.8.0                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pip                       20.1.1                   pypi_0    pypi
prometheus-client         0.7.1                    pypi_0    pypi
prompt-toolkit            3.0.5                    pypi_0    pypi
ptyprocess                0.6.0                    pypi_0    pypi
pygments                  2.6.1                    pypi_0    pypi
pyparsing                 2.4.7                    pypi_0    pypi
pyrsistent                0.16.0                   pypi_0    pypi
python                    3.7.7                hf48f09d_4  
python-dateutil           2.8.1                    pypi_0    pypi
pyzmq                     19.0.1                   pypi_0    pypi
readline                  8.0                  h1de35cc_0  
send2trash                1.5.0                    pypi_0    pypi
setuptools                46.4.0                   pypi_0    pypi
six                       1.14.0                   pypi_0    pypi
sqlite                    3.31.1               h5c1f38d_1  
terminado                 0.8.3                    pypi_0    pypi
testpath                  0.4.4                    pypi_0    pypi
tk                        8.6.8                ha441bb4_0  
tornado                   6.0.4                    pypi_0    pypi
traitlets                 4.3.3                    pypi_0    pypi
wcwidth                   0.1.9                    pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
wheel                     0.34.2                   py37_0  
xz                        5.2.5                h1de35cc_0  
zipp                      3.1.0                    pypi_0    pypi
zlib                      1.2.11               h1de35cc_3  
Referring to this issue and this issue upgrading pyzmq to 19.0.0 and notebook to 6.0.1 didn't fix the issue.