JDK-8214300 : .attach_pid files may remain in the process cwd
  • Type: Bug
  • Component: core-svc
  • Sub-Component: tools
  • Affected Version: 8,9,10,11,12
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-11-26
  • Updated: 2021-05-28
  • Resolved: 2018-12-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 12
12 b23Fixed
Related Reports
Relates :  
Description
On platforms where .attach_pid file is used to initate the attach it may remain in the process cwd after the attach attempt is finished.
Consider the sequence:
- attach process is started, VirtualMachineImpl.createAttachFile creates a file `"/proc/" + pid + "/cwd/" + ".attach_pid" + pid`
- process (pid) dies before we actually attached (and /proc/pid/cwd link is removed)
- after timeout it tries to delete .attach_pid file in the finally block and fail because cwd link from proc is no longer available
And the file remain in the real cwd folder (where /proc/pid/cwd link was pointing).

Comments
Sorry, the patch is for java 8 sourcebase. As far as I can see, the latest sources should also convert to the canonicalFile/Path in the namespace branch where "/proc/" + pid + "/root/" + tmpdir is generated. Linked cwd is not used on windows and mac.
29-11-2018

Which repos does the proposed fix come from? It does not appear to include the jdk/jdk changes which include container namespace adjustments when creating an attach file. Is it true that a linked cwd is used on all target platforms? Using a /proc based path has been used for quite some time now. Seems appropriate for establishing a connection with a live process.
29-11-2018

Possible fix may be: Index: jdk/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- jdk/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java (revision 37b96860b53ec77b2acb5988ea50b3b993ac2f57) +++ jdk/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java (revision d8021d85c73e5eb505cdf4badaca6d196051280d) @@ -282,6 +282,7 @@ String path = "/proc/" + pid + "/cwd/" + fn; File f = new File(path); try { + f = f.getCanonicalFile(); f.createNewFile(); } catch (IOException x) { f = new File(tmpdir, fn); Index: jdk/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- jdk/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java (revision 37b96860b53ec77b2acb5988ea50b3b993ac2f57) +++ jdk/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java (revision d8021d85c73e5eb505cdf4badaca6d196051280d) @@ -279,6 +279,7 @@ String path = "/proc/" + pid + "/cwd/" + fn; File f = new File(path); try { + f = f.getCanonicalFile(); f.createNewFile(); } catch (IOException x) { f = new File(tmpdir, fn); Index: jdk/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- jdk/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java (revision 37b96860b53ec77b2acb5988ea50b3b993ac2f57) +++ jdk/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java (revision d8021d85c73e5eb505cdf4badaca6d196051280d) @@ -233,6 +233,7 @@ String path = "/proc/" + pid + "/cwd/" + fn; File f = new File(path); try { + f = f.getCanonicalFile(); f.createNewFile(); } catch (IOException x) { f = new File(tmpdir, fn);
29-11-2018