playframework/playframework — pull request #1912 by jroper (2013-10-29 06:27:29+00:00)
Title: too many files open bug

Hi guys.
I use play! deployment several projects.when my project running in product env.
running after a period of,the will throw 'Too many files open' exception!
so check my source code,confirm input/output stream all closed.
after a period of groping,I found a bug in play! source code in :
\play-2.1.1\framework\src\iteratees\src\main\scala\play\api\libs\iteratee\Enumerator.scala 603 line.
the mothod:

```scala
def fromStream(input: java.io.InputStream, chunkSize: Int = 1024 * 8) = {
fromCallback(() => {
val buffer = new Array[Byte](chunkSize)
val chunk = input.read(buffer) match {
case -1 => None
case read =>
val input = new Array[Byte](read)
System.arraycopy(buffer, 0, input, 0, read)
Some(input)
}
Future.successful(chunk)
}, input.close)
}
```

the code not closed input stream,when the exception throwed.
so i change the code to:

```scala
def fromStream(input: java.io.InputStream, chunkSize: Int = 1024 * 8) = {
fromCallback(() => {
val buffer = new Array[Byte](chunkSize)
val chunk = input.read(buffer) match {
case -1 => None
case read =>
val input = new Array[Byte](read)
System.arraycopy(buffer, 0, input, 0, read)
Some(input)
}
Future.successful(chunk)
}, input.close,(_:String,_:Input[_]) => input.close)
}
```

the change just only close input stream when socket communication exceptin.

there has been the latest version.