Duplicate handler name: inner

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Duplicate handler name: inner

antrix
I've created a basic ratpack app with a single handler. It seems to work for the first client request but then throws exception:

22:52:54.605 [main] INFO  ratpack.server.RatpackServer - Ratpack started for http://localhost:8080
22:53:16.623 [ratpack-compute-1-3] ERROR ratpack.exec.Execution - Uncaught execution exception
java.lang.IllegalArgumentException: Duplicate handler name: inner
	at io.netty.channel.DefaultChannelPipeline.filterName(DefaultChannelPipeline.java:1066) ~[netty-transport-4.1.0.Beta5.jar:4.1.0.Beta5]
	at io.netty.channel.DefaultChannelPipeline.addLast(DefaultChannelPipeline.java:144) ~[netty-transport-4.1.0.Beta5.jar:4.1.0.Beta5]
	at io.netty.channel.DefaultChannelPipeline.addLast(DefaultChannelPipeline.java:129) ~[netty-transport-4.1.0.Beta5.jar:4.1.0.Beta5]
	at ratpack.server.internal.DefaultRatpackServer$ReloadHandler.delegate(DefaultRatpackServer.java:457) ~[ratpack-core-0.9.17.jar:na]
	at ratpack.server.internal.DefaultRatpackServer$ReloadHandler.lambda$null$231(DefaultRatpackServer.java:436) ~[ratpack-core-0.9.17.jar:na]
	at ratpack.server.internal.DefaultRatpackServer$ReloadHandler$$Lambda$109/317036117.apply(Unknown Source) ~[na:na]
	at ratpack.exec.Promise.lambda$null$41(Promise.java:499) ~[ratpack-core-0.9.17.jar:na]
	at ratpack.exec.Promise$$Lambda$121/468398416.call(Unknown Source) ~[na:na]

I think my handler is getting registered multiple times?

Source here: https://github.com/antrix/biglink/blob/master/src/main/java/net/antrix/BigLinkMain.java
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

danhyun
This seems to be working just fine for me.

The only thing is I'd update this line https://github.com/antrix/biglink/blob/master/src/main/java/net/antrix/UploadHandler.java#L39

to read `ctx.redirect("/");` to let the client know to execute the redirect. A `200` response code is inconsistent with redirecting behavior.

How are you executing this application? I just imported your project as a Maven pom.xml project in IntelliJ and was able to right click on the main class and run.
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

antrix
I'm running from IntelliJ as well.

Did you try to post some valid form data? A couple of times?
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

danhyun
I've modified the line I mentioned then booted up the app.

Here are the steps I took:

1. Navigated to /
2. Uploaded an image
3. Was redirected to /
4. Uploaded a different image
5. Was redirected to /
6. Tried to upload first image
7. Got exception that file already existed

Could you please list your steps to reproduce?
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

antrix
My local copy was a little bit different. In UploadHandler.java:

try (OutputStream out = ... )) {
      uploadedFile.writeTo(out);
      ctx.redirect("/");
} catch (IOException e) {
      ctx.error(e);
}

Essentially, move the redirect to within the block. This gives me the exception I posted. Can you please try this?

As a related question, I thought invoking ctx.error() or ctx.clientError() would terminate request handling immediately but apparently not?
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

danhyun
So this works for me as well using the same steps :/

And yes you're correct in that `ctx.error()` injects the `ServerErrorHandler` into the Handler chain and sends a 500 response to the user.
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

antrix
Hmm. Java 1.8.0_31 - if that matters here :-(
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

danhyun
Could you commit everything you have as is?
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

antrix
Done. Please check the repo again.
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

danhyun
I've pulled the latest code and ran from IntelliJ and cannot reproduce. I've uploaded 10 files using the form from "/" path. What happens if you generate a jar file and execute that? Or maybe try running without a debugger?
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

antrix
This is driving me nuts! I ran from command line using a jar and get the same result! Please pull my latest commit for jar creation changes.

I do need to upload twice or thrice before it triggers. Tried Chrome and Firefox. Tried big and small files.

If it helps, when this exception occurs, it gets thrown on seemingly all of the [ratpack-compute-*] threads simultaneously. The logs are filled with identical stack trace from all the threads.

Full stack trace:

09:00:01.308 [ratpack-compute-1-4] ERROR ratpack.exec.Execution - Uncaught execution exception
java.lang.IllegalArgumentException: Duplicate handler name: inner
        at io.netty.channel.DefaultChannelPipeline.filterName(DefaultChannelPipeline.java:1066) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at io.netty.channel.DefaultChannelPipeline.addLast(DefaultChannelPipeline.java:144) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at io.netty.channel.DefaultChannelPipeline.addLast(DefaultChannelPipeline.java:129) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at ratpack.server.internal.DefaultRatpackServer$ReloadHandler.delegate(DefaultRatpackServer.java:457) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at ratpack.server.internal.DefaultRatpackServer$ReloadHandler.lambda$null$231(DefaultRatpackServer.java:436) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at ratpack.server.internal.DefaultRatpackServer$ReloadHandler$$Lambda$109/614646303.apply(Unknown Source) ~[na:na]
        at ratpack.exec.Promise.lambda$null$41(Promise.java:499) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at ratpack.exec.Promise$$Lambda$121/415729589.call(Unknown Source) ~[na:na]
        at ratpack.exec.internal.DefaultExecControl$2.lambda$get$121(DefaultExecControl.java:157) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at ratpack.exec.internal.DefaultExecControl$2$$Lambda$97/546667832.execute(Unknown Source) ~[na:na]
        at ratpack.exec.internal.ExecutionBacking.intercept(ExecutionBacking.java:279) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at ratpack.exec.internal.DefaultExecControl$2.get(DefaultExecControl.java:156) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at ratpack.exec.internal.DefaultExecControl$2.get(DefaultExecControl.java:149) ~[biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:476) ~[na:1.8.0_31]
        at java.util.concurrent.CompletableFuture$Async.run(CompletableFuture.java:428) ~[na:1.8.0_31]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_31]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_31]
        at ratpack.exec.internal.DefaultExecController$ExecControllerBindingThreadFactory.lambda$newThread$136(DefaultExecController.java:84) [biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at ratpack.exec.internal.DefaultExecController$ExecControllerBindingThreadFactory$$Lambda$81/1523553211.run(Unknown Source) [biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) [biglink-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

antrix
In reply to this post by danhyun
I tried running this on a Linux machine and it works :-/

Perhaps something to do with my Windows 7 setup. But I have no clue what it could be!

Thanks for your help so far.
Reply | Threaded
Open this post in threaded view
|

Re: Duplicate handler name: inner

danhyun
FWIW I'm on Win 8