1

I'm using btrace to instrument an application. What Btrace does is inject bytecode into the running JVM to trace the target application. It also sets up a socket connection to communicate between the tracer client and the application.

When I stop the tracer client it does not remove the code injected into the application. It continues to trace and send back the results over this port. Since client is no longer there any attempts to send trace results generate exception:

java.net.SocketException: Connection reset by peer: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
    at java.io.ObjectOutputStream$BlockDataOutputStream.writeBlockHeader(ObjectOutputStream.java:1894)
    at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1875)
    at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1786)
    at java.io.ObjectOutputStream.reset(ObjectOutputStream.java:500)
    at com.sun.btrace.agent.RemoteClient.onCommand(RemoteClient.java:137)
    at com.sun.btrace.BTraceRuntime$ConsumerWrapper.accept(BTraceRuntime.java:169)
    at com.sun.btrace.BTraceRuntime$ConsumerWrapper.accept(BTraceRuntime.java:157)
    at com.sun.btrace.org.jctools.queues.MpscChunkedArrayQueue.drain(MpscChunkedArrayQueue.java:624)
    at com.sun.btrace.BTraceRuntime$4.run(BTraceRuntime.java:443)
    at java.lang.Thread.run(Thread.java:745)

How can I un-instrument the application and gracefully shutdown btrace after connecting it to an application?

Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169
  • Seems to be a bug. Can you run `btrace -v ...` and attach the log info either here or in the BTrace issue (https://github.com/btraceio/btrace/issues/239)? – JB- Aug 24 '16 at 16:22
  • @J.B I'm not sure if it's a bug. Looking through the source I can see `BTraceEngineImpl` has accepts a Command.EXIT in order to shutdown. But how are these commands supposed to be issued? Over JMX? A better way would be to register for JVM shutdown hook and send this command on exit. – Kshitiz Sharma Aug 24 '16 at 16:46

0 Answers0