When forwardTo is called in a before filter, the action's execute method should not be called #489

Closed
caiiiycuk opened this Issue Dec 15, 2014 · 1 comment

Projects

None yet

2 participants

@caiiiycuk
Contributor

How to reproduce:

  • Checkout xitrum-new
  • Modify SiteIndex.scala, to:
package quickstart.action

import xitrum.annotation.GET

@GET("")
class SiteIndex extends DefaultLayout {

  beforeFilter {
    forwardTo[NotFoundError]()
    false
  }

  def execute() {
    respondView()
  }
}

This code generates execption in runtime:

[WARN] Error
io.netty.util.IllegalReferenceCountException: refCnt: 0
    at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1187) ~[netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.buffer.CompositeByteBuf.checkComponentIndex(CompositeByteBuf.java:306) ~[netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.buffer.CompositeByteBuf.addComponent0(CompositeByteBuf.java:160) ~[netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.buffer.CompositeByteBuf.addComponent(CompositeByteBuf.java:111) ~[netty-all-4.0.24.Final.jar:4.0.24.Final]
    at xitrum.util.ByteBufUtil$.writeComposite(ByteBufUtil.scala:24) ~[xitrum_2.11-3.20.jar:3.20]
    at xitrum.view.Responder$class.respondText(Responder.scala:159) ~[xitrum_2.11-3.20.jar:3.20]
    at quickstart.action.SiteIndex.respondText(SiteIndex.scala:6) [classes/:na]
    at xitrum.view.Responder$class.respondView(Responder.scala:254) ~[xitrum_2.11-3.20.jar:3.20]
    at quickstart.action.SiteIndex.respondView(SiteIndex.scala:6) [classes/:na]
    at xitrum.view.Responder$class.respondView(Responder.scala:270) ~[xitrum_2.11-3.20.jar:3.20]
    at quickstart.action.SiteIndex.respondView(SiteIndex.scala:6) [classes/:na]
    at quickstart.action.SiteIndex.execute(SiteIndex.scala:14) [classes/:na]
    at xitrum.action.Filter$$anonfun$1.apply$mcV$sp(Filter.scala:58) ~[xitrum_2.11-3.20.jar:3.20]
    at xitrum.action.Filter$class.callExecuteWrappedInAroundFilters(Filter.scala:62) ~[xitrum_2.11-3.20.jar:3.20]
    at quickstart.action.SiteIndex.callExecuteWrappedInAroundFilters(SiteIndex.scala:6) [classes/:na]
    at xitrum.Action$class.xitrum$Action$$callExecuteWrappedInAroundFiltersThenAfterFilters(Action.scala:183) ~[xitrum_2.11-3.20.jar:3.20]
    at xitrum.Action$class.dispatchWithFailsafe(Action.scala:108) ~[xitrum_2.11-3.20.jar:3.20]
    at quickstart.action.SiteIndex.dispatchWithFailsafe(SiteIndex.scala:6) [classes/:na]
    at xitrum.handler.inbound.Dispatcher$.dispatch(Dispatcher.scala:45) [xitrum_2.11-3.20.jar:3.20]
    at xitrum.handler.inbound.Dispatcher.channelRead0(Dispatcher.scala:87) [xitrum_2.11-3.20.jar:3.20]
    at xitrum.handler.inbound.Dispatcher.channelRead0(Dispatcher.scala:65) [xitrum_2.11-3.20.jar:3.20]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at xitrum.handler.inbound.MethodOverrider.channelRead0(MethodOverrider.scala:45) [xitrum_2.11-3.20.jar:3.20]
    at xitrum.handler.inbound.MethodOverrider.channelRead0(MethodOverrider.scala:19) [xitrum_2.11-3.20.jar:3.20]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at xitrum.handler.inbound.UriParser.channelRead0(UriParser.scala:33) [xitrum_2.11-3.20.jar:3.20]
    at xitrum.handler.inbound.UriParser.channelRead0(UriParser.scala:16) [xitrum_2.11-3.20.jar:3.20]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at xitrum.handler.inbound.WebJarsServer.channelRead0(WebJarsServer.scala:33) [xitrum_2.11-3.20.jar:3.20]
    at xitrum.handler.inbound.WebJarsServer.channelRead0(WebJarsServer.scala:23) [xitrum_2.11-3.20.jar:3.20]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at xitrum.handler.inbound.PublicFileServer.channelRead0(PublicFileServer.scala:33) [xitrum_2.11-3.20.jar:3.20]
    at xitrum.handler.inbound.PublicFileServer.channelRead0(PublicFileServer.scala:23) [xitrum_2.11-3.20.jar:3.20]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at xitrum.handler.inbound.BaseUrlRemover.channelRead0(BaseUrlRemover.scala:23) [xitrum_2.11-3.20.jar:3.20]
    at xitrum.handler.inbound.BaseUrlRemover.channelRead0(BaseUrlRemover.scala:11) [xitrum_2.11-3.20.jar:3.20]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at xitrum.handler.inbound.Request2Env.sendUpstream(Request2Env.scala:290) [xitrum_2.11-3.20.jar:3.20]
    at xitrum.handler.inbound.Request2Env.channelRead0(Request2Env.scala:101) [xitrum_2.11-3.20.jar:3.20]
    at xitrum.handler.inbound.Request2Env.channelRead0(Request2Env.scala:49) [xitrum_2.11-3.20.jar:3.20]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:161) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) [netty-all-4.0.24.Final.jar:4.0.24.Final]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_65]

Works fine in Xitrum 3.18
Affected version 3.19, 3.20

@ngocdaothanh ngocdaothanh self-assigned this Dec 15, 2014
@ngocdaothanh ngocdaothanh added this to the Xitrum 3.21 milestone Dec 15, 2014
@ngocdaothanh ngocdaothanh added the Bug label Dec 15, 2014
@ngocdaothanh
Member

Thanks for reporting.
It's related to #490.
Xitrum expected that you may respond in beforeFilter, but it didn't expect the use case in which you call forwardTo.

I'll fix this problem and release a new version soon.

@ngocdaothanh ngocdaothanh changed the title from forwardTo in beforeFilter throws exception, since Xitrum 3.19 to When forwardTo is called in a before filter, the action's execute method should not be called Dec 17, 2014
@ngocdaothanh ngocdaothanh added a commit that closed this issue Dec 17, 2014
@ngocdaothanh ngocdaothanh Fix #489 When forwardTo is called in a before filter, the action's ex…
…ecute method should not be called
bb44316
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment