<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">But I also thought you said the delay
      and retry fixed the problem. How could fix the problem if it is
      just duplicating something that is already in place?<br>
      <br>
      Chris<br>
      <br>
      On 10/4/18 9:48 AM, Gary Adams wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:5BB64447.4090408@oracle.com">
      <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
      My delay and retry just duplicated the openDoor retry.<br>
      The normal processing of FileNotFoundException(ENOENT) is to retry<br>
      several times until the file is available.<br>
      <br>
      But the original problem reported is a "Permission denied"
      (EACCESS or EPERM).<br>
      Delay and retry will not resolve a permissions error.<br>
      <br>
      On 10/4/18, 12:30 PM, Chris Plummer wrote:
      <blockquote
        cite="mid:7115147a-2aae-d168-2db5-d1914837f050@oracle.com"
        type="cite">
        <meta http-equiv="Content-Type" content="text/html;
          charset=utf-8">
        <div class="moz-cite-prefix">Didn't the retry after 100ms delay
          work? If yes, why would it if the problem is that a java_pid
          was not cleaned up?<br>
          <br>
          Chris<br>
          <br>
          On 10/4/18 8:54 AM, Gary Adams wrote:<br>
        </div>
        <blockquote type="cite" cite="mid:5BB637A6.6010008@oracle.com">
          <meta content="text/html; charset=utf-8"
            http-equiv="Content-Type">
          First, let me retract the proposed change,<br>
          it is not the right solution to the problem originally<br>
          reported.<br>
          <br>
          Second, as a bit of explanation consider the code fragments
          below.<br>
          <br>
          The high level processing calls openDoor which is willing to
          retry <br>
          the operation as long as the error is flagged specifically<br>
          as a FileNotFoundException.<br>
          <br>
          Â  VirtualMachineImpl.java:72<br>
          Â  VirtualMachineImpl.c:81<br>
          <br>
          During my testing I had added a check
          VirtualMachineImpl.java:214<br>
          and when an IOException was detected made a call to
          checkPermissions<br>
          to get more detailed information about the IOException. The
          error <br>
          I saw was an ENOENT from the stat call. And not the detailed
          checks for<br>
          specific permissions issues (VirtualMachineImpl.c:143)<br>
          <br>
          Â  Â  VirtualMachineImpl.c:118<br>
          Â  Â  VirtualMachineImpl.c:147<br>
          <br>
          What I missed in the original proposed solution was a
          FileNotFoundException<br>
          extends IOException. That means my delay and retry just
          duplicates the higher<br>
          level retry around the openDoor call.<br>
          <br>
          Third, the original error message logged in the bug report :<br>
          <br>
          <span style="caret-color: rgb(51, 51, 51); color: rgb(51, 51,
            51); font-family: Arial, sans-serif; font-size:
            14.000000953674316px; font-style: normal; font-variant-caps:
            normal; font-weight: normal; letter-spacing: normal;
            orphans: auto; text-align: start; text-indent: 0px;
            text-transform: none; white-space: normal; widows: auto;
            word-spacing: 0px; -webkit-text-size-adjust: auto;
            -webkit-text-stroke-width: 0px; background-color: rgb(255,
            255, 255); text-decoration: none; display: inline
            !important; float: none;">java.io.IOException: Permission
            denied<span class="Apple-converted-space"> </span></span><br
            style="caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51);
            font-family: Arial, sans-serif; font-size:
            14.000000953674316px; font-style: normal; font-variant-caps:
            normal; font-weight: normal; letter-spacing: normal;
            orphans: auto; text-align: start; text-indent: 0px;
            text-transform: none; white-space: normal; widows: auto;
            word-spacing: 0px; -webkit-text-size-adjust: auto;
            -webkit-text-stroke-width: 0px; text-decoration: none;">
          <span style="caret-color: rgb(51, 51, 51); color: rgb(51, 51,
            51); font-family: Arial, sans-serif; font-size:
            14.000000953674316px; font-style: normal; font-variant-caps:
            normal; font-weight: normal; letter-spacing: normal;
            orphans: auto; text-align: start; text-indent: 0px;
            text-transform: none; white-space: normal; widows: auto;
            word-spacing: 0px; -webkit-text-size-adjust: auto;
            -webkit-text-stroke-width: 0px; background-color: rgb(255,
            255, 255); text-decoration: none; display: inline
            !important; float: none;">at
            jdk.attach/sun.tools.attach.VirtualMachineImpl.open(Native
            Method)<span class="Apple-converted-space"> </span></span><br>
          <br>
          had to have come from<br>
          <br>
          Â  VirtualMachineImpl.c:70<br>
          Â  VirtualMachineImpl.c:84<br>
          <br>
          which means the actual open call reported the file does exist<br>
          but the permissions do not allow the file to be accessed.<br>
          That also means the normal mechanism of removing leftover <br>
          java_pid files would not have cleaned up another user's<br>
          java_pid files.<br>
          <br>
          =====<br>
src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java:<br>
          ...<br>
          Â Â Â  67    Â Â Â Â Â Â Â  // Opens the door file to the target VM. If
          the file is not<br>
          Â Â Â  68    Â Â Â Â Â Â Â  // found it might mean that the attach
          mechanism isn't started in the<br>
          Â Â Â  69    Â Â Â Â Â Â Â  // target VM so we attempt to start it and
          retry.<br>
          Â Â Â  70    Â Â Â Â Â Â Â  try {<br>
          Â Â Â  71    Â Â Â Â Â Â Â Â Â Â Â  fd = openDoor(pid);<br>
          Â Â Â  72    Â Â Â Â Â Â Â  } catch (FileNotFoundException fnf1) {<br>
          Â Â Â  73    Â Â Â Â Â Â Â Â Â Â Â  File f = createAttachFile(pid);<br>
          Â Â Â  74    Â Â Â Â Â Â Â Â Â Â Â  try {<br>
          Â Â Â  75    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  sigquit(pid);<br>
          Â Â Â  76    <br>
          Â Â Â  77    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  // give the target VM time to start
          the attach mechanism<br>
          Â Â Â  78    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  final int delay_step = 100;<br>
          Â Â Â  79    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  final long timeout =
          attachTimeout();<br>
          Â Â Â  80    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  long time_spend = 0;<br>
          Â Â Â  81    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  long delay = 0;<br>
          Â Â Â  82    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  do {<br>
          Â Â Â  83    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  // Increase timeout on each
          attempt to reduce polling<br>
          Â Â Â  84    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  delay += delay_step;<br>
          Â Â Â  85    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  try {<br>
          Â Â Â  86    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  Thread.sleep(delay);<br>
          Â Â Â  87    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  } catch (InterruptedException x)
          { }<br>
          Â Â Â  88    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  try {<br>
          Â Â Â  89    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  fd = openDoor(pid);<br>
          Â Â Â  90    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  } catch (FileNotFoundException
          fnf2) {<br>
          Â Â Â  91    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  // pass<br>
          Â Â Â  92    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  }<br>
          Â Â Â  93    <br>
          Â Â Â  94    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  time_spend += delay;<br>
          Â Â Â  95    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  if (time_spend > timeout/2
          && fd == -1) {<br>
          Â Â Â  96    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  // Send QUIT again to give
          target VM the last chance to react<br>
          Â Â Â  97    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  sigquit(pid);<br>
          Â Â Â  98    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  }<br>
          Â Â Â  99    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  } while (time_spend <= timeout
          && fd == -1);<br>
          Â Â  100    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  if (fd  == -1) {<br>
          Â Â  101    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  throw new
          AttachNotSupportedException(<br>
          Â Â  102    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  String.format("Unable to
          open door %s: " +<br>
          Â Â  103    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  "target process %d doesn't
          respond within %dms " +<br>
          Â Â  104    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  "or HotSpot VM not
          loaded", socket_path, pid, time_spend));<br>
          Â Â  105    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  }<br>
          ...<br>
          Â Â  212    Â Â Â  // The door is attached to .java_pid<pid>
          in the temporary directory.<br>
          Â Â  213    Â Â Â  private int openDoor(int pid) throws IOException
          {<br>
          Â Â  214    Â Â Â Â Â Â Â  socket_path = tmpdir + "/.java_pid" + pid;<br>
          Â Â  215    Â Â Â Â Â Â Â  fd = open(socket_path);<br>
          Â Â  216    <br>
          Â Â  217    Â Â Â Â Â Â Â  // Check that the file owner/permission to
          avoid attaching to<br>
          Â Â  218    Â Â Â Â Â Â Â  // bogus process<br>
          Â Â  219    Â Â Â Â Â Â Â  try {<br>
          Â Â  220    Â Â Â Â Â Â Â Â Â Â Â  checkPermissions(socket_path);<br>
          Â Â  221    Â Â Â Â Â Â Â  } catch (IOException ioe) {<br>
          Â Â  222    Â Â Â Â Â Â Â Â Â Â Â  close(fd);<br>
          Â Â  223    Â Â Â Â Â Â Â Â Â Â Â  throw ioe;<br>
          Â Â  224    Â Â Â Â Â Â Â  }<br>
          Â Â  225    Â Â Â Â Â Â Â  return fd;<br>
          Â Â  226    Â Â Â  }<br>
          <br>
          =====<br>
          src/jdk.attach/solaris/native/libattach/VirtualMachineImpl.c:<br>
          ...<br>
          Â Â Â  59    JNIEXPORT jint JNICALL
          Java_sun_tools_attach_VirtualMachineImpl_open<br>
          Â Â Â  60    Â  (JNIEnv *env, jclass cls, jstring path)<br>
          Â Â Â  61    {<br>
          Â Â Â  62    Â Â Â  jboolean isCopy;<br>
          Â Â Â  63    Â Â Â  const char* p = GetStringPlatformChars(env,
          path, &isCopy);<br>
          Â Â Â  64    Â Â Â  if (p == NULL) {<br>
          Â Â Â  65    Â Â Â Â Â Â Â  return 0;<br>
          Â Â Â  66    Â Â Â  } else {<br>
          Â Â Â  67    Â Â Â Â Â Â Â  int fd;<br>
          Â Â Â  68    Â Â Â Â Â Â Â  int err = 0;<br>
          Â Â Â  69    <br>
          Â Â Â  70    Â Â Â Â Â Â Â  fd = open(p, O_RDWR);<br>
          Â Â Â  71    Â Â Â Â Â Â Â  if (fd == -1) {<br>
          Â Â Â  72    Â Â Â Â Â Â Â Â Â Â Â  err = errno;<br>
          Â Â Â  73    Â Â Â Â Â Â Â  }<br>
          Â Â Â  74    <br>
          Â Â Â  75    Â Â Â Â Â Â Â  if (isCopy) {<br>
          Â Â Â  76    Â Â Â Â Â Â Â Â Â Â Â  JNU_ReleaseStringPlatformChars(env,
          path, p);<br>
          Â Â Â  77    Â Â Â Â Â Â Â  }<br>
          Â Â Â  78    <br>
          Â Â Â  79    Â Â Â Â Â Â Â  if (fd == -1) {<br>
          Â Â Â  80    Â Â Â Â Â Â Â Â Â Â Â  if (err == ENOENT) {<br>
          Â Â Â  81    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  JNU_ThrowByName(env,
          "java/io/FileNotFoundException", NULL);<br>
          Â Â Â  82    Â Â Â Â Â Â Â Â Â Â Â  } else {<br>
          Â Â Â  83    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  char* msg = strdup(strerror(err));<br>
          Â Â Â  84    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  JNU_ThrowIOException(env, msg);<br>
          Â Â Â  85    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  if (msg != NULL) {<br>
          Â Â Â  86    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  free(msg);<br>
          Â Â Â  87    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  }<br>
          Â Â Â  88    Â Â Â Â Â Â Â Â Â Â Â  }<br>
          Â Â Â  89    Â Â Â Â Â Â Â  }<br>
          Â Â Â  90    Â Â Â Â Â Â Â  return fd;<br>
          Â Â Â  91    Â Â Â  }<br>
          Â Â Â  92    }<br>
          ...<br>
          Â Â Â  99    JNIEXPORT void JNICALL
          Java_sun_tools_attach_VirtualMachineImpl_checkPermissions<br>
          Â Â  100    Â  (JNIEnv *env, jclass cls, jstring path)<br>
          Â Â  101    {<br>
          Â Â  102    Â Â Â  jboolean isCopy;<br>
          Â Â  103    Â Â Â  const char* p = GetStringPlatformChars(env,
          path, &isCopy);<br>
          Â Â  104    Â Â Â  if (p != NULL) {<br>
          Â Â  105    Â Â Â Â Â Â Â  struct stat64 sb;<br>
          Â Â  106    Â Â Â Â Â Â Â  uid_t uid, gid;<br>
          Â Â  107    Â Â Â Â Â Â Â  int res;<br>
          Â Â  108    <br>
          Â Â  109    Â Â Â Â Â Â Â  memset(&sb, 0, sizeof(struct stat64));<br>
          Â Â  110    <br>
          Â Â  111    Â Â Â Â Â Â Â  /*<br>
          Â Â  112    Â Â Â Â Â Â Â Â  * Check that the path is owned by the
          effective uid/gid of this<br>
          Â Â  113    Â Â Â Â Â Â Â Â  * process. Also check that group/other
          access is not allowed.<br>
          Â Â  114    Â Â Â Â Â Â Â Â  */<br>
          Â Â  115    Â Â Â Â Â Â Â  uid = geteuid();<br>
          Â Â  116    Â Â Â Â Â Â Â  gid = getegid();<br>
          Â Â  117    <br>
          Â Â  118    Â Â Â Â Â Â Â  res = stat64(p, &sb);<br>
          Â Â  119    Â Â Â Â Â Â Â  if (res != 0) {<br>
          Â Â  120    Â Â Â Â Â Â Â Â Â Â Â  /* save errno */<br>
          Â Â  121    Â Â Â Â Â Â Â Â Â Â Â  res = errno;<br>
          Â Â  122    Â Â Â Â Â Â Â  }<br>
          Â Â  123    <br>
          Â Â  124    Â Â Â Â Â Â Â  if (res == 0) {<br>
          Â Â  125    Â Â Â Â Â Â Â Â Â Â Â  char msg[100];<br>
          Â Â  126    Â Â Â Â Â Â Â Â Â Â Â  jboolean isError = JNI_FALSE;<br>
          Â Â  127    Â Â Â Â Â Â Â Â Â Â Â  if (sb.st_uid != uid && uid !=
          ROOT_UID) {<br>
          Â Â  128    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  snprintf(msg, sizeof(msg),<br>
          Â Â  129    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  "file should be owned by the
          current user (which is %d) but is owned by %d", uid,
          sb.st_uid);<br>
          Â Â  130    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  isError = JNI_TRUE;<br>
          Â Â  131    Â Â Â Â Â Â Â Â Â Â Â  } else if (sb.st_gid != gid &&
          uid != ROOT_UID) {<br>
          Â Â  132    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  snprintf(msg, sizeof(msg),<br>
          Â Â  133    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  "file's group should be the
          current group (which is %d) but the group is %d", gid,
          sb.st_gid);<br>
          Â Â  134    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  isError = JNI_TRUE;<br>
          Â Â  135    Â Â Â Â Â Â Â Â Â Â Â  } else if ((sb.st_mode &
          (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) {<br>
          Â Â  136    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  snprintf(msg, sizeof(msg),<br>
          Â Â  137    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  "file should only be readable
          and writable by the owner but has 0%03o access", sb.st_mode
          & 0777);<br>
          Â Â  138    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  isError = JNI_TRUE;<br>
          Â Â  139    Â Â Â Â Â Â Â Â Â Â Â  }<br>
          Â Â  140    Â Â Â Â Â Â Â Â Â Â Â  if (isError) {<br>
          Â Â  141    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  char buf[256];<br>
          Â Â  142    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  snprintf(buf, sizeof(buf),
          "well-known file %s is not secure: %s", p, msg);<br>
          Â Â  143    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  JNU_ThrowIOException(env, buf);<br>
          Â Â  144    Â Â Â Â Â Â Â Â Â Â Â  }<br>
          Â Â  145    Â Â Â Â Â Â Â  } else {<br>
          Â Â  146    Â Â Â Â Â Â Â Â Â Â Â  char* msg = strdup(strerror(res));<br>
          Â Â  147    Â Â Â Â Â Â Â Â Â Â Â  JNU_ThrowIOException(env, msg);<br>
          Â Â  148    Â Â Â Â Â Â Â Â Â Â Â  if (msg != NULL) {<br>
          Â Â  149    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  free(msg);<br>
          Â Â  150    Â Â Â Â Â Â Â Â Â Â Â  }<br>
          Â Â  151    Â Â Â Â Â Â Â  }<br>
          <br>
          On 10/2/18, 6:23 PM, David Holmes wrote:
          <blockquote
            cite="mid:e1adb28a-031f-5c28-74a5-451718a7683b@oracle.com"
            type="cite">Minor correction: EPERM -> EACCES for Solaris
            <br>
            <br>
            Hard to see how to get a transient EACCES when opening a
            file ... though as it is really a door I guess there could
            be additional complexity. <br>
            <br>
            David <br>
            <br>
            On 3/10/2018 7:54 AM, Chris Plummer wrote: <br>
            <blockquote type="cite">On 10/2/18 2:38 PM, David Holmes
              wrote: <br>
              <blockquote type="cite">Chris, <br>
                <br>
                On 3/10/2018 6:57 AM, Chris Plummer wrote: <br>
                <blockquote type="cite"> <br>
                  <br>
                  On 10/2/18 1:44 PM, <a
                    class="moz-txt-link-abbreviated"
                    href="mailto:gary.adams@oracle.com"
                    moz-do-not-send="true">gary.adams@oracle.com</a>
                  wrote: <br>
                  <blockquote type="cite">The general attach sequence
                    ... <br>
                    <br>
src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java
                    <br>
                    <br>
                    Â the attacher creates an attach_pid file in a
                    directory where the attachee is runnning <br>
                    Â issues a signal to the attacheee <br>
                    <br>
                    Â  loops waiting for the java_pid file to be created
                    <br>
                    Â  default timeout is 10 seconds <br>
                    <br>
                  </blockquote>
                  So getting a FileNotFoundException while in this loop
                  is OK, but IOException is not. <br>
                  <br>
                  <blockquote type="cite">src/hotspot/os/solaris/attachListener_solaris.cpp
                    <br>
                    <br>
                    Â Â  attachee creates the java_pid file <br>
                    Â Â  listens til the attacher opens the door <br>
                    <br>
                  </blockquote>
                  I'm don't think this is related, but JDK-8199811 made
                  a fix in attachListener_solaris.cpp to make it wait up
                  to 10 seconds for initialization to complete before
                  failing the enqueue. <br>
                  <br>
                  <blockquote type="cite">... <br>
                    Not sure when a bare IOException is thrown rather
                    than the <br>
                    more specific FileNotFoundException. <br>
                  </blockquote>
                  Where is the IOException originating from? I wonder if
                  the issue is that the file is in the process of being
                  created, but is not fully created yet. Maybe it is
                  there, but owner/group/permissions have not been set
                  yet, and this results in an IOException instead of
                  FileNotFoundException. <br>
                </blockquote>
                <br>
                The exception is shown in the bug report: <br>
                <br>
                Â [java.io.IOException: Permission denied <br>
                at
                jdk.attach/sun.tools.attach.VirtualMachineImpl.open(Native
                Method) <br>
                at
jdk.attach/sun.tools.attach.VirtualMachineImpl.openDoor(VirtualMachineImpl.java:215)
                <br>
                at
jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:71)
                <br>
                at
jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
                <br>
                at
jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
                <br>
                at
                jdk.jcmd/sun.tools.jcmd.JCmd.executeCommandForPid(JCmd.java:114)
                <br>
                at jdk.jcmd/sun.tools.jcmd.JCmd.main(JCmd.java:98) <br>
                <br>
                And if you look at the native code the EPERM from open
                will cause IOException to be thrown. <br>
                <br>
./jdk.attach/solaris/native/libattach/VirtualMachineImpl.c <br>
                <br>
                JNIEXPORT jint JNICALL
                Java_sun_tools_attach_VirtualMachineImpl_open <br>
                Â  (JNIEnv *env, jclass cls, jstring path) <br>
                { <br>
                Â Â Â  jboolean isCopy; <br>
                Â Â Â  const char* p = GetStringPlatformChars(env, path,
                &isCopy); <br>
                Â Â Â  if (p == NULL) { <br>
                Â Â Â Â Â Â Â  return 0; <br>
                Â Â Â  } else { <br>
                Â Â Â Â Â Â Â  int fd; <br>
                Â Â Â Â Â Â Â  int err = 0; <br>
                <br>
                Â Â Â Â Â Â Â  fd = open(p, O_RDWR); <br>
                Â Â Â Â Â Â Â  if (fd == -1) { <br>
                Â Â Â Â Â Â Â Â Â Â Â  err = errno; <br>
                Â Â Â Â Â Â Â  } <br>
                <br>
                Â Â Â Â Â Â Â  if (isCopy) { <br>
                Â Â Â Â Â Â Â Â Â Â Â  JNU_ReleaseStringPlatformChars(env, path,
                p); <br>
                Â Â Â Â Â Â Â  } <br>
                <br>
                Â Â Â Â Â Â Â  if (fd == -1) { <br>
                Â Â Â Â Â Â Â Â Â Â Â  if (err == ENOENT) { <br>
                Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  JNU_ThrowByName(env,
                "java/io/FileNotFoundException", NULL); <br>
                Â Â Â Â Â Â Â Â Â Â Â  } else { <br>
                Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  char* msg = strdup(strerror(err)); <br>
                Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  JNU_ThrowIOException(env, msg); <br>
                Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  if (msg != NULL) { <br>
                Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  free(msg); <br>
                Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  } <br>
                <br>
                <br>
                We should add the path to the exception message. <br>
                <br>
              </blockquote>
              Thanks David. So if EPERM is the error and a retry 100ms
              later works, I think that supports my hypothesis that the
              file is not quite fully created. So Gary's fix is probably
              fine. The only other possible fix I can think of that
              wouldn't require an explicit delay (or multiple retries)
              is probably not worth the complexity. It would require
              that the attachee create two files, and the attacher try
              to open the second file first. When it either opens or
              returns EPERM, you know the first file can safety be
              opened. <br>
              <br>
              Chris <br>
              <blockquote type="cite">David <br>
                ----- <br>
                <br>
                <blockquote type="cite">Chris <br>
                  <blockquote type="cite"> <br>
                    <br>
                    <br>
                    On 10/2/18 4:11 PM, Chris Plummer wrote: <br>
                    <blockquote type="cite">Can you summarize how the
                      attach handshaking is suppose to work? I'm just
                      wondering why the attacher would ever be looking
                      for the file before the attachee has created it.
                      It seems a proper handshake would prevent this.
                      Maybe there's some sort of visibility issue where
                      the attachee has indeed created the file, but it
                      is not immediately visible to the attacher
                      process. <br>
                      <br>
                      Chris <br>
                      <br>
                      On 10/2/18 12:27 PM, <a
                        class="moz-txt-link-abbreviated"
                        href="mailto:gary.adams@oracle.com"
                        moz-do-not-send="true">gary.adams@oracle.com</a>
                      wrote: <br>
                      <blockquote type="cite">The problem reproduced
                        pretty quickly. <br>
                        I added a call to checkPermission and revealed
                        the <br>
                        "file not found" from the stat call when the
                        IOException <br>
                        was detected. <br>
                        <br>
                        There has been some flakiness from the Solaris
                        test machines today, <br>
                        so I'll continue with the testing a bit longer.
                        <br>
                        <br>
                        On 10/2/18 3:12 PM, Chris Plummer wrote: <br>
                        <blockquote type="cite">Without the fix was this
                          issue easy enough to reproduce that you can be
                          sure this is resolving it? <br>
                          <br>
                          Chris <br>
                          <br>
                          On 10/2/18 8:16 AM, Gary Adams wrote: <br>
                          <blockquote type="cite">Solaris debug builds
                            are failing tests that use the attach
                            interface. <br>
                            An IOException is reported when the java_pid
                            file is not opened. <br>
                            <br>
                            It appears that the attempt to attach is
                            taking place too quickly. <br>
                            This workaround will allow the open
                            operation to be retried <br>
                            after a short pause. <br>
                            <br>
                            Â  Webrev: <a class="moz-txt-link-freetext"
href="http://cr.openjdk.java.net/%7Egadams/8210337/webrev/"
                              moz-do-not-send="true">http://cr.openjdk.java.net/~gadams/8210337/webrev/</a>
                            <br>
                            Â  Issue: <a class="moz-txt-link-freetext"
                              href="https://bugs.openjdk.java.net/browse/JDK-8210337"
                              moz-do-not-send="true">https://bugs.openjdk.java.net/browse/JDK-8210337</a>
                            <br>
                            <br>
                            Testing is in progress. <br>
                          </blockquote>
                          <br>
                          <br>
                          <br>
                        </blockquote>
                        <br>
                      </blockquote>
                      <br>
                      <br>
                    </blockquote>
                    <br>
                  </blockquote>
                  <br>
                  <br>
                </blockquote>
              </blockquote>
              <br>
              <br>
            </blockquote>
          </blockquote>
          <br>
        </blockquote>
        <p><br>
        </p>
      </blockquote>
      <br>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>