karatelabs / vscode-extension

Karate Visual Studio Code Extension
https://marketplace.visualstudio.com/items?itemName=karatelabs.karate
9 stars 1 forks source link

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

Open j8d opened 7 months ago

j8d commented 7 months ago

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 commented 7 months ago

@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 commented 7 months ago

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 commented 7 months ago

@j8d thanks we'll tale a look

ptrthomas commented 7 months ago

@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: https://github.com/karatelabs/karate/issues/2546

j8d commented 7 months ago

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;

  2. 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
  3. Add a breakpoint to the second feature (log.feature)

  4. 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 commented 7 months ago

Also, when debugging Java...

image

ptrthomas commented 7 months ago

@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 commented 7 months ago

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 commented 6 months ago

@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: https://github.com/karatelabs/karate/issues/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