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

Debug error: io.karatelabs.debug.DapServerHandler is not a @Sharable handler, so can't be added or removed multiple times #22

Open
j8d opened this issue Apr 11, 2024 · 9 comments

Comments

@j8d
Copy link

j8d commented Apr 11, 2024

Getting the error below trying to start a single debug session via CodeLense. It was working fine until yesterday afternoon.

12:06:12.126 [main] INFO com.intuit.karate - Karate version: 1.5.0.RC3
debug server started on port: 34407
12:06:12.855 [nioEventLoopGroup-3-2] WARN i.n.ide.channel.ChannelInitializer - Failed to initialize a channel. Closing: [id: 0x2e6606b3, L:/127.0.0.1:34407 - R:/127.0.0.1:36912]
io.netty.ide.channel.ChannelPipelineException: io.karatelabs.debug.DapServerHandler is not a @sharable handler, so can't be added or removed multiple times.
at io.netty.ide.channel.DefaultChannelPipeline.checkMultiplicity(DefaultChannelPipeline.java:600)
at io.netty.ide.channel.DefaultChannelPipeline.addLast(DefaultChannelPipeline.java:202)
at io.netty.ide.channel.DefaultChannelPipeline.addLast(DefaultChannelPipeline.java:381)
at io.netty.ide.channel.DefaultChannelPipeline.addLast(DefaultChannelPipeline.java:370)
at io.karatelabs.debug.DapServer$1.initChannel(DapServer.java:61)
at io.netty.ide.channel.ChannelInitializer.initChannel(ChannelInitializer.java:129)
at io.netty.ide.channel.ChannelInitializer.handlerAdded(ChannelInitializer.java:112)
at io.netty.ide.channel.AbstractChannelHandlerContext.callHandlerAdded(AbstractChannelHandlerContext.java:1130)
at io.netty.ide.channel.DefaultChannelPipeline.callHandlerAdded0(DefaultChannelPipeline.java:609)
at io.netty.ide.channel.DefaultChannelPipeline.access$100(DefaultChannelPipeline.java:46)
at io.netty.ide.channel.DefaultChannelPipeline$PendingHandlerAddedTask.execute(DefaultChannelPipeline.java:1463)
at io.netty.ide.channel.DefaultChannelPipeline.callHandlerAddedForAllHandlers(DefaultChannelPipeline.java:1115)
at io.netty.ide.channel.DefaultChannelPipeline.invokeHandlerAddedIfNeeded(DefaultChannelPipeline.java:650)
at io.netty.ide.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:514)
at io.netty.ide.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:429)
at io.netty.ide.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:486)
at io.netty.ide.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
at io.netty.ide.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
at io.netty.ide.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
at io.netty.ide.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
at io.netty.ide.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.ide.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.ide.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:840)

@ptrthomas
Copy link
Member

@j8d thanks, we'll do our best to investigate but this will be hard to replicate.

by any chance did something change in your environment - say like an OS upgrade ? recently Java on the Mac has had some interesting issues.

@j8d
Copy link
Author

j8d commented Apr 12, 2024

After messing with it some more, I found out the error occurs when I place a break point in a feature that gets called before the feature I initiate the debug session from. Also, vscode is running on WSL on Windows 10.

image

image

Actually, log.feature gets called even before this as it's called from features called from karate-config.js

@ptrthomas
Copy link
Member

@j8d thanks we'll tale a look

@ptrthomas
Copy link
Member

@j8d can you try the patch release we built from here: https://github.com/karatelabs/vscode-extension/releases/tag/v2.0.5 - it should fix this problem, let me know

by the way you certainly seem to be using JS + Java interop a lot - please be aware of this development: karatelabs/karate#2546

@j8d
Copy link
Author

j8d commented Apr 15, 2024

Thank you @ptrthomas - that fix resolved the DapServerHandler error. But, annoyingly, that error was apparently just a red herring for the issue I'm actually facing, It's possible it's an edge case that's not worth investigating, but here's what I've found...

  1. Call a feature (classpath:helpers/Okta.feature) from karate-config:

var result = karate.callSingle('classpath:helpers/Okta.feature@referral', config);
config.token = result.token;

  1. From that feature (classpath:helpers/Okta.feature), call another feature (classpath:helpers/log.feature):

    • def info = karate.info
    • call read('classpath:helpers/log.feature') info
  2. Add a breakpoint to the second feature (log.feature)

  3. Start a debug session from a third feature in the runner path (classpath:features/some.feature)

The breakpoint in log.feature will cause the process to hang. It appears to be pausing at the breakpoint but not enabling the options in vscode to continue past it.

image

@j8d
Copy link
Author

j8d commented Apr 15, 2024

Also, when debugging Java...

image

@ptrthomas
Copy link
Member

@j8d yes it may be an edge case. I suspect a second "instance" of a debug session is being created somewhere, but hard to figure out. there's actually a debug log you can switch on, please refer: https://github.com/karatelabs/vscode-extension#troubleshooting - so if you can paste the log or screenshot for that (in DEBUG) that may provide some clues

else I'm voting to close this. unless you have the time to provide a quickstart project where this can be replicated, but I know that can be hard

@j8d
Copy link
Author

j8d commented Apr 16, 2024

Replicated in https://github.com/j8d/vscode-extension-issue-22/tree/main/src/test/java/examples/users

users.feature is called from kartate-config.js
users2 is called from users

Add a breakpoint in users2 then debug from users3 and it will hang

@ptrthomas
Copy link
Member

ptrthomas commented May 10, 2024

@j8d apologies for the delay on this. I think the reason is anything within a JS function currently has to execute within a global JVM lock. this is why this happens for things within karate-config.js because it is a JS function. this problem should be resolved with the work here: karatelabs/karate#2546

so until then any breakpoints within karate-config.js may have this issue. until the lock is released no other JS can be evaluated. in the long term we hope to even support stepping through JS blocks

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

No branches or pull requests

2 participants