title: Stanford CoreNLP server using 12 threads, 6 clients calling it and yet sometime “Only one usage of each socket address is normally permitted” error
body: <p>Stanford CoreNLP server is using 12 threads, I have 6 mono-threaded clients calling it and yet I sometime get the error message:</p>
  <blockquote>
  <p>Failed to establish a new connection: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted'))</p>
  </blockquote>
  <p>How is it possible? I thought it would be safe to run up to 12 clients simultaneously since the Stanford CoreNLP server is using 12 threads and my clients only use 1 thread each.</p>
  <hr />
  <p>I launch the Stanford CoreNLP server using:</p>
  <pre><code> java -mx4g -cp &quot;*&quot; edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9001 -timeout 50000
  </code></pre>
  <p>which starts the Stanford CoreNLP server with 12 threads as I have 12 CPU cores (and I can see that Stanford CoreNLP server mentions it will use 12 threads).</p>
  <p>The code I used to call the Stanford CoreNLP server is:</p>
  <pre><code>import os
  import json
  from pycorenlp import StanfordCoreNLP
  import time
  import sys
  nlp = StanfordCoreNLP('http://localhost:9001')
  total_start_time = time.time()
  
  for i in range(9999999):
      text = 'without the dataset the paper {0} is useless'.format(i)
      print('text: {0}'.format(text))
      start_time = time.time()
      output = nlp.annotate(text, properties={
          'annotators': 'ner',
          'outputFormat': 'json'
      })
      elapsed_time = time.time() - start_time
      print('elapsed_time: {0:.4f} seconds'.format(elapsed_time))
  
  print('total_start_time: {0:.4f} seconds'.format(time.time()-total_start_time))
  </code></pre>
  <p>The entire error stack is below. The script is called <code>parse_captions.py</code> and it has a few more lines of code that the code I gave above, so the line numbers don't match. Also, the text being parsed is different.</p>
  <pre><code>text: anniversary of the liquidation of the litzmanstadt ghetto in lodz
  Traceback (most recent call last):
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py&quot;, line 159, in _new_conn
      (self._dns_host, self.port), self.timeout, **extra_kw)
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\connection.py&quot;, line 80, in create_connection
      raise err
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\connection.py&quot;, line 70, in create_connection
      sock.connect(sa)
  OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py&quot;, line 600, in urlopen
      chunked=chunked)
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py&quot;, line 354, in _make_request
      conn.request(method, url, **httplib_request_kw)
    File &quot;C:\ProgramData\Anaconda3\lib\http\client.py&quot;, line 1229, in request
      self._send_request(method, url, body, headers, encode_chunked)
    File &quot;C:\ProgramData\Anaconda3\lib\http\client.py&quot;, line 1275, in _send_request
      self.endheaders(body, encode_chunked=encode_chunked)
    File &quot;C:\ProgramData\Anaconda3\lib\http\client.py&quot;, line 1224, in endheaders
      self._send_output(message_body, encode_chunked=encode_chunked)
    File &quot;C:\ProgramData\Anaconda3\lib\http\client.py&quot;, line 1016, in _send_output
      self.send(msg)
    File &quot;C:\ProgramData\Anaconda3\lib\http\client.py&quot;, line 956, in send
      self.connect()
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py&quot;, line 181, in connect
      conn = self._new_conn()
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py&quot;, line 168, in _new_conn
      self, &quot;Failed to establish a new connection: %s&quot; % e)
  urllib3.exceptions.NewConnectionError: &lt;urllib3.connection.HTTPConnection object at 0x000002660423E780&gt;: Failed to establish a new connection: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py&quot;, line 449, in send
      timeout=timeout
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py&quot;, line 638, in urlopen
      _stacktrace=sys.exc_info()[2])
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\retry.py&quot;, line 398, in increment
      raise MaxRetryError(_pool, url, error or ResponseError(cause))
  urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=9001): Max retries exceeded with url: /?properties=%7B%27annotators%27%3A+%27tokenize%2Cssplit%2Cpos%2Cdepparse%2Ctruecase%2Cparse%27%2C+%27outputFormat%27%3A+%27json%27%7D (Caused by NewConnectionError('&lt;urllib3.connection.HTTPConnection object at 0x000002660423E780&gt;: Failed to establish a new connection: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted'))
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;parse_captions.py&quot;, line 52, in &lt;module&gt;
      main()
    File &quot;parse_captions.py&quot;, line 37, in main
      'outputFormat': 'json'
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\pycorenlp\corenlp.py&quot;, line 29, in annotate
      }, data=data, headers={'Connection': 'close'})
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py&quot;, line 116, in post
      return request('post', url, data=data, json=json, **kwargs)
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py&quot;, line 60, in request
      return session.request(method=method, url=url, **kwargs)
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py&quot;, line 533, in request
      resp = self.send(prep, **send_kwargs)
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py&quot;, line 646, in send
      r = adapter.send(request, **kwargs)
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py&quot;, line 516, in send
      raise ConnectionError(e, request=request)
  requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9001): Max retries exceeded with url: /?properties=%7B%27annotators%27%3A+%27tokenize%2Cssplit%2Cpos%2Cdepparse%2Ctruecase%2Cparse%27%2C+%27outputFormat%27%3A+%27json%27%7D (Caused by NewConnectionError('&lt;urllib3.connection.HTTPConnection object at 0x000002660423E780&gt;: Failed to establish a new connection: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted'))
  </code></pre>
  <p>I use Python 3.7.3 x64, Stanford CoreNLP version 3.9.2 (i.e., 2018-10-05) and Microsoft Windows 18.09 &quot;Professional&quot;.</p>