Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public TerminalService addTerminalService(TerminalSocket terminalSocket) {
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);
LOGGER.error(terminalSocket2Service.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
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;
Expand Down Expand Up @@ -148,6 +149,39 @@ public void onTerminalResize(String columns, String rows) {
}
}

@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);
Expand Down
Loading