title: Uvicorn + Gunicorn + Starlette is getting stuck when serving, can't restart the service without sigkill
body: <p>I am serving a model on a VM through gunicorn + uvicorn.</p>
  <p>It is automatically started by supervisord, running <code>api.sh</code>.</p>
  <p><code>api.sh</code> contains:</p>
  <pre><code>source /home/asd/.virtual_envs/myproject/bin/activate
  
  /home/asd/.virtual_envs/myproject/bin/gunicorn --max-requests-jitter 30 -w 6 -b 0.0.0.0:4080 api:app -k uvicorn.workers.UvicornWorker
  </code></pre>
  <p>Without getting too much into <code>api.py</code>, it contains these main parts:</p>
  <pre><code>from starlette.applications import Starlette
  from models import SomeModelClass
  
  
  app = Starlette(debug=False)
  model = SomeModelClass()
  
  
  @app.route('/do_things', methods=['GET', 'POST', 'HEAD'])
  async def add_styles(request):
      if request.method == 'GET':
          params = request.query_params
      elif request.method == 'POST':
          params = await request.json()
      elif request.method == 'HEAD':
          return UJSONResponse([])
  
      # Doing things
      result = model(params)
      return UJSONResponse(result)
  </code></pre>
  <p>What happens is that I start getting these errors after the api is up for a few days:</p>
  <pre><code>[INFO] Starting gunicorn 20.0.3
  [ERROR] Connection in use: ('0.0.0.0', 4080)
  [ERROR] Retrying in 1 second.
  [ERROR] Connection in use: ('0.0.0.0', 4080)
  [ERROR] Retrying in 1 second.
  [ERROR] Connection in use: ('0.0.0.0', 4080)
  [ERROR] Retrying in 1 second.
  [ERROR] Connection in use: ('0.0.0.0', 4080)
  [ERROR] Retrying in 1 second.
  ...
  </code></pre>
  <p>Restarting api in supervisord does nothing, I get the same messages as above. The only way I found that works is:</p>
  <ol>
  <li>Stop api in supervisord</li>
  <li>See which pid is running on 4080 port (a <code>python3.8</code> process): <code>sudo netstat -tulpn | grep LISTEN</code></li>
  <li>Kill it running <code>kill -9 [PID]</code></li>
  <li>Repeat steps 2-3 for 1-2 times till nothing takes up the 4080 port</li>
  <li>Start the api in supervisord</li>
  </ol>
  <p>Do you have any ideas how to solve this?</p>