Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually terminate the Py4JServer during engine shutdown #4644

Closed
wants to merge 2 commits into from

Conversation

cfmcgrady
Copy link
Contributor

Why are the changes needed?

Due to the Py4JServer initiating with a non-daemon thread, there is a possibility of it impeding the engine's termination. Therefore, it is imperative to manually terminate the Py4JServer during engine shutdown.

"Thread-23" #96 prio=5 os_prio=0 cpu=7.93ms elapsed=187532.67s tid=0x00007fee840cf000 nid=0x8f runnable  [0x00007fedca6bf000]
   java.lang.Thread.State: RUNNABLE
	at java.net.PlainSocketImpl.socketAccept(java.base@11.0.16/Native Method)
	at java.net.AbstractPlainSocketImpl.accept(java.base@11.0.16/Unknown Source)
	at java.net.ServerSocket.implAccept(java.base@11.0.16/Unknown Source)
	at java.net.ServerSocket.accept(java.base@11.0.16/Unknown Source)
	at py4j.GatewayServer.run(GatewayServer.java:685)
	at java.lang.Thread.run(java.base@11.0.16/Unknown Source)

How was this patch tested?

  • Add some test cases that check the changes thoroughly including negative and positive cases if possible

  • Add screenshots for manual tests if appropriate

  • Run test locally before make a pull request

@cfmcgrady cfmcgrady changed the title Manually terminate the Py4JServer during engine shutdown. Manually terminate the Py4JServer during engine shutdown Mar 31, 2023
@yaooqinn
Copy link
Member

the start and stop need to be syncronized

@cfmcgrady
Copy link
Contributor Author

the start and stop need to be syncronized

The start function has already been synchronized in the caller's code, shall we need to refine this?

private val isPythonGatewayStart = new AtomicBoolean(false)
private val kyuubiPythonPath = Utils.createTempDir()
def init(): Unit = {
if (!isPythonGatewayStart.get()) {
synchronized {
if (!isPythonGatewayStart.get()) {
KyuubiPythonGatewayServer.start()
writeTempPyFile(kyuubiPythonPath, "execute_python.py")
writeTempPyFile(kyuubiPythonPath, "kyuubi_util.py")
isPythonGatewayStart.set(true)
}
}
}
}

@cfmcgrady
Copy link
Contributor Author

the start and stop need to be syncronized

updated.

@pan3793 pan3793 added this to the v1.7.1 milestone Mar 31, 2023
@pan3793 pan3793 closed this in 726a831 Mar 31, 2023
pan3793 pushed a commit that referenced this pull request Mar 31, 2023
### _Why are the changes needed?_

Due to the Py4JServer initiating with a non-daemon thread, there is a possibility of it impeding the engine's termination. Therefore, it is imperative to manually terminate the Py4JServer during engine shutdown.

```
"Thread-23" #96 prio=5 os_prio=0 cpu=7.93ms elapsed=187532.67s tid=0x00007fee840cf000 nid=0x8f runnable  [0x00007fedca6bf000]
   java.lang.Thread.State: RUNNABLE
	at java.net.PlainSocketImpl.socketAccept(java.base11.0.16/Native Method)
	at java.net.AbstractPlainSocketImpl.accept(java.base11.0.16/Unknown Source)
	at java.net.ServerSocket.implAccept(java.base11.0.16/Unknown Source)
	at java.net.ServerSocket.accept(java.base11.0.16/Unknown Source)
	at py4j.GatewayServer.run(GatewayServer.java:685)
	at java.lang.Thread.run(java.base11.0.16/Unknown Source)
```

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [x] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #4644 from cfmcgrady/pyserver-non-daemon.

Closes #4644

d4f1a57 [Fu Chen] synchronized
cdc9630 [Fu Chen] shutdown Py4JServer

Authored-by: Fu Chen <cfmcgrady@gmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
(cherry picked from commit 726a831)
Signed-off-by: Cheng Pan <chengpan@apache.org>
@pan3793
Copy link
Member

pan3793 commented Mar 31, 2023

Thanks, merged to master/1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants