JDK-4790817 : Create specific Exception for SIGINT signal in Selector.select()
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2002-12-09
  • Updated: 2002-12-09
  • Resolved: 2002-12-09
Related Reports
Relates :  
Description

Name: nt126004			Date: 12/09/2002


FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

FULL OPERATING SYSTEM VERSION :
Linux
glibc-2.2.4-24 (not really relevant here..)

A DESCRIPTION OF THE PROBLEM :
The Selector implementation throws a generic
IOException when a SIGINT (^C) is received while
blocking on the select() method.

Specifically, it is thrown at
sun.nio.ch.PollArrayWrapper.poll0 (native)
w/ "Interrupted system call" as its message.

This behavior is within the spec. I think, however,
it would be better if something more specific were
thrown.

I noticed this when writing a shutdown hook (a la
Runtime.addShutdownHook ) for a non-blocking server
and discovering that my exception handling was not
working as I had intended.

For now, I have to inspect the exception message
in order to tell whether the exception is being
thrown as a result of receiving SIGINT.  This is not
pretty and is certainly fragile.

I suggest, therefore, that a more specific IOException
(say something akin to the ClosedByInterruptException)
be thrown when these types of signals cause the
select() operation to fail, and then to document it
in the API.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Write some code that blocks indefinitely on a selection
operation
2.Run the program, and wait 'till the selection operation is
reached
3.Kill the program with ^C
4.Examine the stack trace

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER WORKAROUND :
Examine the message in the IOException to detect
whether the exception was thrown as a result of
SIGINT
(Review ID: 178496) 
======================================================================

Comments
EVALUATION Will not fix. EINTR should never be exposed in this way -- interrupted system calls should instead be restarted (4504001). -- ###@###.### 2002/12/9
12-10-0175