scala - Exception caught in RequestBodyHandler -
below code when user uploads video mobile application s3
def uploadvideo = action(parse.multipartformdata) { implicit request => try { var height = 0 var width = 0 request.body.files.map { mov => var videoname = system.currenttimemillis() + ".mpeg" amazons3client.putobject(bucketvideos, videoname, mov.ref.file) } val map = map("result" -> "success") ok(write(map)) } catch { case e: exception => ok(write(map("result" -> "error"))) } }
the above code work fine in case user cancel while uploading of video error occurs
[error] play - exception caught in requestbodyhandler java.nio.channels.closedchannelexception: null @ org.jboss.netty.channel.socket.nio.abstractnioworker.cleanupwritebuffer(abstractnioworker.java:434) ~[netty.jar:na] @ org.jboss.netty.channel.socket.nio.abstractnioworker.writefromusercode(abstractnioworker.java:129) ~[netty.jar:na] @ org.jboss.netty.channel.socket.nio.nioserversocketpipelinesink.handleacceptedsocket(nioserversocketpipelinesink.java:99) ~[netty.jar:na] @ org.jboss.netty.channel.socket.nio.nioserversocketpipelinesink.eventsunk(nioserversocketpipelinesink.java:36) ~[netty.jar:na] @ org.jboss.netty.channel.channels.write(channels.java:725) ~[netty.jar:na] @ org.jboss.netty.handler.codec.oneone.onetooneencoder.doencode(onetooneencoder.java:71) ~[netty.jar:na]
and doesn't go catch block!!
1.can harmfull server or not?(because not needed response if error occours)
2.if yes, how handle?
this happening in play's internals handling parsing body of request
. in fact, during upload server, haven't reached try
block yet because file hasn't finished uploading. once upload complete have temporaryfile
available.
so no, can't catch error, , why want to? user closed connection. they're not waiting response, why send one? let play handle it.
this not way of handling upload, though. small files, it's passable, if proxying huge video upload through server s3, it's going to:
- take twice long serve response (which cause user hang while upload s3).
- block 1 of play's threads handling requests entire time file uploading s3, , given enough of these uploads (not many @ all), no longer able process requests until upload has completed.
consider @ least creating separate executioncontext use handling uploads, or better, having user upload directly s3 via signed form, remove need proxy upload @ all.
Comments
Post a Comment