United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-5100121 (se) select not immune to EINTR
JDK-5100121 : (se) select not immune to EINTR

Details
Type:
Bug
Submit Date:
2004-09-10
Status:
Resolved
Updated Date:
2008-06-20
Project Name:
JDK
Resolved Date:
2004-11-21
Component:
core-libs
OS:
solaris_9,linux_redhat_2.1,solaris_10,linux_2.6
Sub-Component:
java.nio
CPU:
x86,sparc,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
9.1ee,1.4.2_05,6
Fixed Versions:
1.4.2_07 (b02)

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Duplicate:
Duplicate:
Duplicate:
Relates:
Relates:

Sub Tasks

Description
One of Java developer hits one case of BugID#4504001.
It's sun.nio.ch.SelectorImpl.select case.

  BugID#4504001 Check NIO native code to ensure that it restarts any sys calls

The information for the environment and stack trace are below.

====== message =========================================================
[Env]
 JDK version: J2EE1.4.2_05
 JAVA option: -server
 Operating System : RedHat Linux Advanced Server

[Stacktrace at the IOException]

 2004-08-16 20:27:25,931 [ERROR] java.io.IOException: Interrupted system call
 at sun.nio.ch.PollArrayWrapper.poll0(Native Method)
 at sun.nio.ch.PollArrayWrapper.poll(PollArrayWrapper.java:100)
 at sun.nio.ch.PollSelectorImpl.doSelect(PollSelectorImpl.java:64)
 at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:59)
 at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:70)
 at 
jp.co.nttcom.raspberry.integration.systemconnection.inbound.socket.SocketEisInbo
undAccepter.run(SocketEisInboundAccepter.java:292)
(jp.co.nttcom.raspberry.integration.systemconnection.inbound.socket.SocketEisInb
oundAccepter)
======================================================================
###@###.### 10/6/04 21:41 GMT

                                    

Comments
EVALUATION

Restart poll after interruption.


###@###.### 2004-09-24
                                     
2004-09-24
SUGGESTED FIX

*** src/solaris/native/sun/nio/ch/PollArrayWrapper.c-    Mon Sep 27 11:29:41 2004
--- PollArrayWrapper.c  Mon Sep 27 11:22:33 2004

*** 9,30 ****
  #include "jni_util.h"
  #include "jvm.h"
  #include "jlong.h"
  #include "sun_nio_ch_PollArrayWrapper.h"
  #include <poll.h>
  
  
  JNIEXPORT jint JNICALL 
  Java_sun_nio_ch_PollArrayWrapper_poll0(JNIEnv *env, jobject this,
                                         jlong address, jint numfds,
                                         jlong timeout)
  {
      struct pollfd *a;
      int err = 0;
  
      a = (struct pollfd *) jlong_to_ptr(address);
!     err = poll(a, numfds, timeout);
  
      if (err < 0)
          JNU_ThrowIOExceptionWithLastError(env, "Poll failed");
      return (jint)err;
  }
--- 9,58 ----
  #include "jni_util.h"
  #include "jvm.h"
  #include "jlong.h"
  #include "sun_nio_ch_PollArrayWrapper.h"
  #include <poll.h>
+ #include <unistd.h>
+ #include <sys/time.h>
  
+ static jint
+ ipoll(struct pollfd fds[], unsigned int nfds, int timeout)
+ {
+     jlong start, now;
+     jlong remaining = timeout;
+     struct timeval t;
  
+     gettimeofday(&t, NULL);
+     start = t.tv_sec * 1000 + t.tv_usec / 1000;
+ 
+     for (;;) {
+       int res = poll(fds, nfds, remaining);
+       if (res < 0 && errno == EINTR) {
+           if (remaining >= 0) {
+               gettimeofday(&t, NULL);
+               now = t.tv_sec * 1000 + t.tv_usec / 1000;
+               remaining -= now - start;
+               if (remaining <= 0)
+                   return 0;
+               start = now;
+           }
+       } else {
+           return res;
+       }
+     }
+ }
+ 
  JNIEXPORT jint JNICALL 
  Java_sun_nio_ch_PollArrayWrapper_poll0(JNIEnv *env, jobject this,
                                         jlong address, jint numfds,
                                         jlong timeout)
  {
      struct pollfd *a;
      int err = 0;
  
      a = (struct pollfd *) jlong_to_ptr(address);
!     err = ipoll(a, numfds, timeout);
  
      if (err < 0)
          JNU_ThrowIOExceptionWithLastError(env, "Poll failed");
      return (jint)err;
  }

###@###.### 2004-09-27
                                     
2004-09-27
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.4.2_07
1.5.0_01

FIXED IN:
1.4.2_07
1.5.0_01


                                     
2004-10-02
EVALUATION

Although the bug was reported against Linux, the issue also exists on Solaris. When this fix is forward ported to mustang it needs to address the issue for Solaris too.
                                     
2005-11-09



Hardware and Software, Engineered to Work Together