stanfordnlp / stanza

Stanford NLP Python library for tokenization, sentence segmentation, NER, and parsing of many human languages
https://stanfordnlp.github.io/stanza/
Other
7.21k stars 885 forks source link

CoreNLP server fails to shutdown #895

Open OscartGiles opened 2 years ago

OscartGiles commented 2 years ago

Describe the bug We're using Stanza in a package called netts. However, on some windows machines, we're finding the CoreNLP server does not shut down correctly (port is not freed).

To test this I created this repo which simply:

  1. Starts the CoreNLP server and then shuts it down.
  2. Re-run step 1.

There is an action on the repo that successfully does this on a Windows machine.

However, our collaborator has reported that this reliably fails on their machine with error on step 2:

2021-11-22 11:53:39 WARNING: Directory C:\Users\sem91\stanza_corenlp already exists. Please install CoreNLP to a new directory. 2021-11-22 11:53:39 INFO: Writing properties to tmp file: corenlp_server-61ac4e8a74c84ed1.props Traceback (most recent call last): File "C:\Users\sem91\anaconda3\lib\site-packages\stanza\server\client.py", line 132, in start sock.bind((self.host, self.port)) OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions During handling of the above exception, another exception occurred: Traceback (most recent call last): File ".\run.py", line 9, in client.start() File "C:\Users\sem91\anaconda3\lib\site-packages\stanza\server\client.py", line 140, in start "(possibly something is already running there)" % self.port) stanza.server.client.PermanentlyFailedException: Error: unable to start the CoreNLP server on port 9000 (possibly something is already running there)

See below for machine details.

I'm not sure if this is the right place as I don't think you actually maintain the CoreNLP server. But has anyone reported similar issues?

Expected behavior A clear and concise description of what you expected to happen.

Should be able to run this script twice in a row with no errors

Environment (please complete the following information):

Edition Windows 10 Enterprise Version 20H2 Installed on ‎25/‎11/‎2020 OS build 19042.1237 Experience Windows Feature Experience Pack 120.2212.3530.0 8Gb Java: version 8 update 271 (build 1.8.0_271-b09)

Additional context Add any other context about the problem here.

AngledLuffa commented 2 years ago

It is my unique pleasure to maintain the CoreNLP server as well.  However, I simply can't reproduce this error.  I am also running Windows 10.  If I do python bar.py && python bar.py in an emacs shell, or do python bar.py; python bar.py in a Windows PowerShell, or simply duplicate the launching script twice and run python bar2.py, the result is the same - happy launching, closing, and relaunching of the server. 

What did your client do to run the script twice?

Is there some possibility the mechanism where your client runs the server leaves behind a half-dead process? For example, the first answer here suggests that the port will be kept until the child processes are completely cleaned up: https://serverfault.com/questions/181015/how-do-you-free-up-a-port-being-held-open-by-dead-process

serenalotreck commented 1 year ago

I just wanted to say that I believe I'm also experiencing this error. I'm running my script with Python 3.6.4 on a high-performance computing cluster, that's running CentOS Linux 7 (Core) with the following specs:

LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.9.2009 (Core) Release: 7.9.2009 Codename: Core

I first ran my script with python myscript.py -h to get the argument options, and it printed the following output:

2023-01-26 16:46:07 INFO: Installing CoreNLP package into /mnt/home/lotrecks/stanza_corenlp
Downloading https://huggingface.co/stanfordnlp/CoreNLP/resolve/main/stanford-corenlp-latest.zip: 100%

I then tried to run the script normally (python myscript.py <arguments>), and got the same error as @OscartGiles:

2023-01-26 16:56:15 WARNING: Directory /mnt/home/lotrecks/stanza_corenlp already exists. Please install CoreNLP to a new directory.
2023-01-26 16:56:15 INFO: Writing properties to tmp file: corenlp_server-d9ba518dba214f60.props
Traceback (most recent call last):
  File "/mnt/ufs18/home-118/lotrecks/haai_lab/obie-wan/obiewan/lib/python3.6/site-packages/stanza/server/client.py", line 135, in start
    sock.bind((self.host, self.port))
OSError: [Errno 98] Address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "stanford_openie_rels.py", line 230, in <module>
    args.graph, args.graph_out_loc)
  File "stanford_openie_rels.py", line 177, in main
    with CoreNLPClient(annotators=["openie"], output_format="json") as client:
  File "/mnt/ufs18/home-118/lotrecks/haai_lab/obie-wan/obiewan/lib/python3.6/site-packages/stanza/server/client.py", line 188, in __enter__
    self.start()
  File "/mnt/ufs18/home-118/lotrecks/haai_lab/obie-wan/obiewan/lib/python3.6/site-packages/stanza/server/client.py", line 143, in start
    "(possibly something is already running there)" % self.port)
stanza.server.client.PermanentlyFailedException: Error: unable to start the CoreNLP server on port 9000 (possibly something is already running there)

If there's anything I can help you do to reproduce the bug that I didn't add here, let me know!

AngledLuffa commented 1 year ago

Is there a java process running already? Better yet, what happens if you netstat that port?

https://www.ibm.com/support/pages/how-can-i-check-if-application-listening-port-and-applications-name

serenalotreck commented 1 year ago

@AngledLuffa I set the project aside for a while, and when I next came back and ran it, the code ran with no problems (I changed nothing in the interim, and only ran the script a single time). If it happens again in the future I'll netstat the port and post the results here!

EDIT: Came back to this a day later and am running into the same issue. I don't have sudo permissions on the server I'm on (so I can't see the PID of processes bound to the port), but running netstat -tuln | grep :9000 yields the following:

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN
serenalotreck commented 1 year ago

@AngledLuffa just wanted to follow up on this -- I'm continuing to have the same issue, wondering if anyone has been able to reproduce this or if you have any thoughts of how to get around it? It's starting to become a major issue in our project pipeline.

AngledLuffa commented 1 year ago

If there's any way to help reproduce this, I can give it a try, but I can't remember ever encountering it myself