title: JMeter and Python bottle - not closing sockets
body: <p>We've got an API, written in Python and using Bottle and Cherrypy, which we need to stress test.  We've created a JMeter script to do this, but after a couple of minutes of execution, the calls begin to fail with the following exception:-</p>
  
  <pre><code>java.net.BindException: Address already in use: connect
  at java.net.DualStackPlainSocketImpl.connect0(Native Method)
  at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
  at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
  at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
  at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
  at java.net.PlainSocketImpl.connect(Unknown Source)
  at java.net.SocksSocketImpl.connect(Unknown Source)
  at java.net.Socket.connect(Unknown Source)
  </code></pre>
  
  <p>I can't seem to work out how to tell JMeter not to hang onto the sockets, or how to tell Bottle to drop them.  We've tried it with options such as JMeter's KeepAlive on and off but without success.</p>
  
  <p>We've pulled almost everything out of the API and this script still has the problem (without any of our functional baggage).</p>
  
  <pre><code>"""
  This script provides a dummy API, which responds to every GET as if it found something.
  """
  
  import bottle
  import os
  import sys
  import datetime
  import routes
  
  if __name__ == '__main__':
      HOST = 'localhost'
      PORT = 5555
  
      @bottle.route('/thing/:id', builtin_function_or_method='GET')
      def get_thing(id):
          response_json = {
              'data': {
                  'type': 'thing',
                  'id': id,
                  'meta': {
                      'date_retrieved': datetime.datetime.now().isoformat()
                  }
              }
          }
          bottle.response.headers['Cache-Control'] = 'public,max-age=0'
          return response_json
  
      bottle.run(server='cherrypy', host=HOST, port=PORT)
  </code></pre>
  
  <p>This is Python 3.6.5, Cherrypy 8.9.1 and JMeter 3.3 running on Windows.</p>