Skip to content

Commit 95515e9

Browse files
gaborbernatvladak
authored andcommitted
Fix zombie ctags processes by adding waitFor() after destroyForcibly()
When ctags processing times out or is terminated, destroyForcibly() sends SIGKILL but the parent never calls waitFor() to reap the child process. This causes zombie processes to accumulate over long indexing runs. Extract destroyProcess() helper that calls destroyForcibly() followed by waitFor(10, SECONDS) to properly reap terminated ctags processes. Fixes #4920
1 parent ab2190c commit 95515e9

File tree

1 file changed

+15
-3
lines changed
  • opengrok-indexer/src/main/java/org/opengrok/indexer/analysis

1 file changed

+15
-3
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/Ctags.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,19 @@ public void close() {
142142
if (ctagsProcess != null) {
143143
closing = true;
144144
LOGGER.log(Level.FINE, "Destroying ctags command");
145-
ctagsProcess.destroyForcibly();
145+
destroyProcess();
146+
}
147+
}
148+
149+
private void destroyProcess() {
150+
ctagsProcess.destroyForcibly();
151+
try {
152+
if (!ctagsProcess.waitFor(10, TimeUnit.SECONDS)) {
153+
LOGGER.log(Level.WARNING, "ctags process did not terminate within timeout");
154+
}
155+
} catch (InterruptedException e) {
156+
LOGGER.log(Level.WARNING, "Interrupted while waiting for ctags process to terminate");
157+
Thread.currentThread().interrupt();
146158
}
147159
}
148160

@@ -603,10 +615,10 @@ private void readTags(CtagsReader reader) throws InterruptedException {
603615
}
604616
} catch (IllegalThreadStateException e) {
605617
LOGGER.log(Level.WARNING, "ctags EOF but did not exit");
606-
ctagsProcess.destroyForcibly();
618+
destroyProcess();
607619
} catch (Exception e) {
608620
LOGGER.log(Level.WARNING, "ctags problem:", e);
609-
ctagsProcess.destroyForcibly();
621+
destroyProcess();
610622
}
611623
// Throw the following to indicate non-I/O error for retry.
612624
throw new InterruptedException("tagLine == null");

0 commit comments

Comments
 (0)