scala - ClosedChannel Exception -
i have following scala code:
var cf:channelfuture = try { tlog().info(" before channel write ...........{} {}", _channel.isopen, _channel.getconfig.getconnecttimeoutmillis) _channel.write(rsp) } catch { case e:closedchannelexception => tlog.error("closedchannelexception thrown: nettytrigger @line 97") null case e:throwable => tlog.error("", e) null } if (inp != null) try { tlog().info(" before channel if *** write ...........{} {}", _channel.isopen, _channel.getconfig.getconnecttimeoutmillis) cf= _channel.write(new chunkedstream(inp)) } catch { case e:closedchannelexception => tlog.error("closedchannelexception thrown: nettytrigger @line 107") case e:throwable => tlog.error("", e) }
when put load on our server throw below error :
2014-11-30 23:22:38 [new i/o worker #12] error c.z.blason.io.eventemitter - java.nio.channels.closedchannelexception: null @ org.jboss.netty.handler.stream.chunkedwritehandler.discard(chunkedwritehandler.java:168) ~[netty-3.6.5.final.jar:na] @ org.jboss.netty.handler.stream.chunkedwritehandler.flush(chunkedwritehandler.java:192) ~[netty-3.6.5.final.jar:na] @ org.jboss.netty.handler.stream.chunkedwritehandler.handledownstream(chunkedwritehandler.java:121) ~[netty-3.6.5.final.jar:na] @ org.jboss.netty.channel.channels.write(channels.java:704) ~[netty-3.6.5.final.jar:na] @ org.jboss.netty.channel.channels.write(channels.java:671) ~[netty-3.6.5.final.jar:na] @ org.jboss.netty.channel.abstractchannel.write(abstractchannel.java:248) ~[netty-3.6.5.final.jar:na] @ com.zotoh.blason.io.nettytrigger.reply(nettytrigger.scala:97) ~[blason-0.0.3-snapshot.jar:na] @ com.zotoh.blason.io.nettytrigger.resumewithresult(nettytrigger.scala:64) ~[blason-0.0.3-snapshot.jar:na] @ com.zotoh.blason.io.asyncwaitevent.resumeonresult(asyncwaitevent.scala:40) ~[blason-0.0.3-snapshot.jar:na] @ com.zotoh.blason.io.abstractevent.setresult(abstractevent.scala:58) ~[blason-0.0.3-snapshot.jar:na] @ com.zotoh.blason.io.httpevent.setresult(httpevent.scala:76) ~[blason-0.0.3-snapshot.jar:na] @ com.narvar.services.tracking.abstractcarrierservice.htmlassingletrack(abstractcarrierservice.scala:757) ~[classes/:na] @ com.narvar.carriers.ups.tracking.carrierservice.com$narvar$carriers$ups$tracking$carrierservice$$onsingle(carrierservice.scala:76) ~[classes/:na] @ com.narvar.carriers.ups.tracking.carrierservice$$anonfun$1.apply(carrierservice.scala:62) ~[classes/:na] @ com.narvar.carriers.ups.tracking.carrierservice$$anonfun$1.apply(carrierservice.scala:56) ~[classes/:na] @ com.narvar.services.tracking.abstractcarrierservice.evalstatus(abstractcarrierservice.scala:658) ~[classes/:na] @ com.narvar.carriers.ups.tracking.carrierservice.processreply(carrierservice.scala:56) ~[classes/:na] @ com.narvar.workflow.tracking.formatresult$$anon$1.eval(formatresult.scala:41) ~[classes/:na] @ com.zotoh.blason.wflow.work.perform(work.scala:39) ~[blason-0.0.3-snapshot.jar:na] @ com.zotoh.blason.wflow.ptaskstep.eval(ptaskstep.scala:43) ~[blason-0.0.3-snapshot.jar:na] @ com.zotoh.blason.wflow.flowstep.run(flowstep.scala:101) ~[blason-0.0.3-snapshot.jar:na] @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) [na:1.7.0_17] @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) [na:1.7.0_17] @ java.lang.thread.run(thread.java:722) [na:1.7.0_17]
why throwing exception?
closedchannelexception
here means write attempt has been failed because channel has been closed. obviously, cannot write closed channel. looking stack trace, chunkedwritehandler.discard()
has marked current write operation failure because current channel not connected anymore.
to avoid exception, should not close connection before written out.
however, it's impossible practically because connection can closed due many reasons , of them inevitable. you'd better write code deal exception in robust manner. it's trying tell connection closed before transfer finished.
Comments
Post a Comment