Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as.File has File Descriptor leak #119

Closed
seraphr opened this issue Sep 7, 2015 · 3 comments · Fixed by #162
Closed

as.File has File Descriptor leak #119

seraphr opened this issue Sep 7, 2015 · 3 comments · Fixed by #162

Comments

@seraphr
Copy link

seraphr commented Sep 7, 2015

When http request is failed, java.io.RandomAccessFile is not closed.

https://github.com/dispatch/reboot/blob/master/core/src/main/scala/as/core.scala#L35

@Sciss
Copy link

Sciss commented Mar 25, 2017

Is there any workaround?

@seraphr
Copy link
Author

seraphr commented Mar 25, 2017

@Sciss
I wrote alternative implementation.

object AsFile {
  def apply(file: java.io.File) = {
    val tFile = new java.io.RandomAccessFile(file, "rw")
    (new client.resumable.ResumableAsyncHandler with OkHandler[Nothing] {
      override def onThrowable(t: Throwable): Unit = {
        super.onThrowable(t)
        try tFile.close() catch { case e: Throwable => }
      }
    }).setResumableListener(
      new client.extra.ResumableRandomAccessFileListener(
        tFile
      )
    )
  }
}

@Sciss
Copy link

Sciss commented Mar 25, 2017

Thanks - I'm also having a custom AsFile-like thing now (https://gist.github.com/Sciss/bea9022d90a4f0ad7556e8fa283ff459) as I want to monitor download progress, so adding that onThrowable is straight forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants