[
https://issues.apache.org/jira/browse/TIKA-5040?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18138619#comment-18138619
]
ASF GitHub Bot commented on TIKA-5040:
--------------------------------------
dpol1 commented on PR #3532:
URL: https://github.com/apache/tika/pull/3532#issuecomment-6654441896
Thanks, Tim. The second start-time lookup was redundant: the [JDK 17
implementation](https://github.com/openjdk/jdk17u/blob/b84391a2df6cf9fff72c1580502dd7b2b1838dd6/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c#L306-L318)
checks it before killing . I removed that lookup and the Descendant record in
87c9980acd, and changed checkCommandWithTimeout to use
destroyForciblyWithDescendants.
I kept the post-listing isAlive() check because descendant discovery uses
the parent's PID, which may have been reused, and isAlive() compares the start
time. I also kept the unknown-start-time filter: the JDK permits killing when
that information is unavailable. Your bot is right about the trade-off: if the
parent exits during listing, we discard its descendants. I prefer that risk to
killing an unrelated process.
> Orphaned external processes after a forked server is killed or ProcessUtils
> stops waiting
> -----------------------------------------------------------------------------------------
>
> Key: TIKA-5040
> URL: https://issues.apache.org/jira/browse/TIKA-5040
> Project: Tika
> Issue Type: Bug
> Components: tika-core, tika-pipes
> Affects Versions: 4.2.0
> Reporter: Davide Polato
> Priority: Minor
> Fix For: 4.3.0
>
>
> In looking at how to stop a running parse (TIKA-4795), I found that killing a
> forked pipes server leaves its external processes running.
> PerClientServerManager and SharedServerManager kill the server with
> destroyForcibly, which is SIGKILL on Linux. ProcessUtils kills the processes
> it started in execute()'s finally block or in a shutdown hook. SIGKILL ends
> the JVM before either runs.
> When the server exits on its own, the hook runs, but it kills only the direct
> process. With {{sh -c 'sleep 300; true'}}, the sleep keeps running. The
> timeout and interrupt paths of ProcessUtils.execute have the same gap.
> TIKA-3103 shows what this costs: orphaned tesseract processes at 100% CPU for
> over ten minutes.
> I have tests that reproduce each case on main. I'll open a PR that also kills
> the descendants, via ProcessHandle.descendants(), in both server managers and
> wherever ProcessUtils kills a process.
> TesseractOCRParser uses a separate hook in AbstractExternalProcessParser. I'd
> leave that for a follow-up, unless you'd rather have it in this PR?
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)