This is an automated email from the ASF dual-hosted git repository.
voidmatcha pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 69f9e4a653 [ZEPPELIN-6691] Terminate shell terminal process on
WebSocket close
69f9e4a653 is described below
commit 69f9e4a653e9fb04287a39b3cb317b07e28d3180
Author: SeungYoung Oh <[email protected]>
AuthorDate: Sat Sep 5 10:00:12 2026 +0900
[ZEPPELIN-6691] Terminate shell terminal process on WebSocket close
### What is this PR for?
This PR ensures that the `PtyProcess` created for the interactive shell
terminal in the Shell Interpreter is terminated when the terminal WebSocket is
closed.
Previously, the process was not closed when the terminal was closed. This
could allow shell processes to accumulate in the background.
### What type of PR is it?
Bug Fix
### Todos
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-6691
### How should this be tested?
Run a paragraph with `%sh.terminal` and confirm that a shell terminal
process is started.
Move away from the notebook page or close the browser tab, then confirm
that the same process exits.
### Screenshots (if appropriate)
### Questions:
* Does the license files need to update? N
* Is there breaking changes for older versions? N
* Does this needs documentation? N
Closes #5447 from seung-00/ZEPPELIN-6691.
Signed-off-by: YONGJAE LEE <[email protected]>
---
.../zeppelin/shell/terminal/TerminalManager.java | 2 +-
.../shell/terminal/service/TerminalService.java | 36 +++++++++++++++++++++-
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git
a/shell/src/main/java/org/apache/zeppelin/shell/terminal/TerminalManager.java
b/shell/src/main/java/org/apache/zeppelin/shell/terminal/TerminalManager.java
index 95ac46e6b3..71d9ff1279 100644
---
a/shell/src/main/java/org/apache/zeppelin/shell/terminal/TerminalManager.java
+++
b/shell/src/main/java/org/apache/zeppelin/shell/terminal/TerminalManager.java
@@ -69,7 +69,7 @@ public class TerminalManager {
public void removeTerminalService(TerminalSocket terminalSocket) {
Integer terminalSocketHashcode = terminalSocket.hashCode();
if (terminalSocket2Service.containsKey(terminalSocketHashcode)) {
- terminalSocket2Service.remove(terminalSocketHashcode);
+ terminalSocket2Service.remove(terminalSocketHashcode).close();
} else {
LOGGER.error("Can't find TerminalSocket: {}", terminalSocketHashcode);
}
diff --git
a/shell/src/main/java/org/apache/zeppelin/shell/terminal/service/TerminalService.java
b/shell/src/main/java/org/apache/zeppelin/shell/terminal/service/TerminalService.java
index d473c7c5d3..609dbe91a6 100644
---
a/shell/src/main/java/org/apache/zeppelin/shell/terminal/service/TerminalService.java
+++
b/shell/src/main/java/org/apache/zeppelin/shell/terminal/service/TerminalService.java
@@ -35,8 +35,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
-public class TerminalService {
+public class TerminalService implements AutoCloseable {
private static final Logger LOGGER =
LoggerFactory.getLogger(TerminalService.class);
private String[] termCommand;
@@ -148,6 +149,39 @@ public class TerminalService {
}
}
+ @Override
+ public void close() {
+ try {
+ if (outputWriter != null) {
+ outputWriter.close();
+ }
+ if (inputReader != null) {
+ inputReader.close();
+ }
+ if (errorReader != null) {
+ errorReader.close();
+ }
+ } catch (IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ }
+
+ if (process != null) {
+ destroyProcess(process);
+ }
+ }
+
+ private void destroyProcess(PtyProcess process) {
+ process.destroy();
+ try {
+ if (!process.waitFor(5L, TimeUnit.SECONDS)) {
+ process.destroyForcibly();
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ process.destroyForcibly();
+ }
+ }
+
public void onWebSocketConnect(Session webSocketSession) {
this.webSocketSession = webSocketSession;
webSocketSession.setMaxIdleTimeout(60 * 60 * 1000);