arthas icon indicating copy to clipboard operation
arthas copied to clipboard

AnsiLog 的 static 初始化可能抛出异常

Open hengyunabc opened this issue 1 year ago • 1 comments

参考这个: https://github.com/alibaba/arthas/issues/1686#issuecomment-1822430841

我们的找到问题了。 有个研发写的代码,强制把slot=0的shutdown hook位置占了。

SharedSecrets.getJavaLangAccess.registerShutdownHook(0, false, xx);

导致arthas的AnsiLog的class load异常,

    static {
        if (System.console() != null) {
            enableColor = true;
            // windows dos, do not support color
            if (OSUtils.isWindows()) {
                enableColor = false;
            }
        }
        // cygwin and mingw support color
        if (OSUtils.isCygwinOrMinGW()) {
            enableColor = true;
        }
    }

从而导致ArthasBootstrap的bind端口失败,所以后边就连不上端口了:

    private ArthasBootstrap(Instrumentation instrumentation, Map<String, String> args) throws Throwable {
        this.instrumentation = instrumentation;

        initFastjson();

        // 1. initSpy()
        initSpy();
        // 2. ArthasEnvironment
        initArthasEnvironment(args);

        String outputPathStr = configure.getOutputPath();
        if (outputPathStr == null) {
            outputPathStr = ArthasConstants.ARTHAS_OUTPUT;
        }
        outputPath = new File(outputPathStr);
        outputPath.mkdirs();

        // 3. init logger
        loggerContext = LogUtil.initLogger(arthasEnvironment);//异常

        // 4. 增强ClassLoader
        enhanceClassLoader();
        // 5. init beans
        initBeans();

        // 6. start agent server
        bind(configure);//bind端口失败
......
    }

hengyunabc avatar Nov 28 '23 07:11 hengyunabc

就加个catch能解决问题吗?这个slot=0的shutdown hook位置,不还是被占着么

iyangpengyu avatar Jan 25 '24 02:01 iyangpengyu