Spring Boot微服务(JDK11)抛出hystrix.stream-actuator-endpoint异常

时间:2019-04-16 08:01:23

标签: java spring-boot hystrix java-11

在将Spring Boot服务迁移到2.1.3.RELEASEjdk11之后,发生与hystrix流执行器相关的异常。

例外是ERROR org.apache.catalina.core.ContainerBase.[Tomcat-1].[localhost].[/].[hystrix.stream-actuator-endpoint] - Servlet.service() for servlet [hystrix.stream-actuator-endpoint] in context with path [] threw exception[]


春季启动版本:2.1.3.RELEASE

Java版本:11

所有执行器端点均暴露:management.endpoints.web.exposure.include=*

此外,hystrix.stream端点实际上已启用并提供流。 尽管如此,日志中仍然会发生异常


堆栈跟踪:

java.nio.BufferOverflowException
    at java.base/java.nio.DirectByteBuffer.put(DirectByteBuffer.java:410)
    at java.base/java.nio.DirectByteBuffer.put(DirectByteBuffer.java:389)
    at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:74)
    at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:50)
    at java.base/sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:466)
    at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:134)
    at org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector.java:105)
    at org.apache.tomcat.util.net.NioSelectorPool.write(NioSelectorPool.java:144)
    at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.doWrite(NioEndpoint.java:1223)
    at org.apache.tomcat.util.net.SocketWrapperBase.doWrite(SocketWrapperBase.java:743)
    at org.apache.tomcat.util.net.SocketWrapperBase.flushBlocking(SocketWrapperBase.java:696)
    at org.apache.tomcat.util.net.SocketWrapperBase.flush(SocketWrapperBase.java:686)
    at org.apache.coyote.http11.Http11OutputBuffer$SocketOutputBuffer.flush(Http11OutputBuffer.java:553)
    at org.apache.coyote.http11.filters.ChunkedOutputFilter.flush(ChunkedOutputFilter.java:157)
    at org.apache.coyote.http11.Http11OutputBuffer.flush(Http11OutputBuffer.java:216)
    at org.apache.coyote.http11.Http11Processor.flush(Http11Processor.java:1149)
    at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:394)
    at org.apache.coyote.Response.action(Response.java:209)
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:295)
    at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:262)
    at org.apache.catalina.connector.CoyoteWriter.flush(CoyoteWriter.java:94)
    at org.apache.catalina.connector.CoyoteWriter.checkError(CoyoteWriter.java:119)
    at com.netflix.hystrix.contrib.sample.stream.HystrixSampleSseServlet.handleRequest(HystrixSampleSseServlet.java:165)
    at com.netflix.hystrix.contrib.sample.stream.HystrixSampleSseServlet.doGet(HystrixSampleSseServlet.java:74)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:834)

和一个类似的

java.lang.IllegalArgumentException: newPosition > limit: (3850 > 532)
    at java.base/java.nio.Buffer.createPositionException(Buffer.java:318)
    at java.base/java.nio.Buffer.position(Buffer.java:293)
    at java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1086)
    at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:82)
    at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:50)
    at java.base/sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:466)
    at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:134)
    at org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector.java:105)
    at org.apache.tomcat.util.net.NioSelectorPool.write(NioSelectorPool.java:144)
    at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.doWrite(NioEndpoint.java:1223)
    at org.apache.tomcat.util.net.SocketWrapperBase.doWrite(SocketWrapperBase.java:743)
    at org.apache.tomcat.util.net.SocketWrapperBase.flushBlocking(SocketWrapperBase.java:696)
    at org.apache.tomcat.util.net.SocketWrapperBase.flush(SocketWrapperBase.java:686)
    at org.apache.coyote.http11.Http11OutputBuffer$SocketOutputBuffer.flush(Http11OutputBuffer.java:553)
    at org.apache.coyote.http11.filters.ChunkedOutputFilter.flush(ChunkedOutputFilter.java:157)
    at org.apache.coyote.http11.Http11OutputBuffer.flush(Http11OutputBuffer.java:216)
    at org.apache.coyote.http11.Http11Processor.flush(Http11Processor.java:1149)
    at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:394)
    at org.apache.coyote.Response.action(Response.java:209)
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:295)
    at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:262)
    at org.apache.catalina.connector.CoyoteWriter.flush(CoyoteWriter.java:94)
    at com.netflix.hystrix.contrib.sample.stream.HystrixSampleSseServlet.handleRequest(HystrixSampleSseServlet.java:168)
    at com.netflix.hystrix.contrib.sample.stream.HystrixSampleSseServlet.doGet(HystrixSampleSseServlet.java:74)

1 个答案:

答案 0 :(得分:0)

运行最小配置,我无法重现该问题,我也尝试将版本从2.1.3-RELEASE切换到2.2.2-RELEASE。没问题。因此,我认为您应该在此处提供更多详细信息。在哪里执行您的应用程序?嵌入式tomcat,外部tomcat,docker?请尝试提供更多详细信息。


无论如何,这是我的测试配置。

pom.xml

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.robman</groupId>
    <artifactId>demohystrix</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demohystrix</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <java.version>11</java.version>

        <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

application.properties

management.endpoints.web.exposure.include=*  

DemoHystrixApplication.java

@SpringBootApplication
@EnableHystrix
@RestController
public class DemoHystrixApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoHystrixApplication.class, args);
    }

    @RequestMapping(value = "/")
    @HystrixCommand(fallbackMethod = "fallback", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000")
    })

    public String hello() throws InterruptedException {
        Thread.sleep(3000);
        return "HELLO Hystrix";
    }

    private String fallback() {
        return "Fallback";
    }

}

如果您使用的是Eureka服务器:
Official docs

  

删除了Eureka服务器所依赖的JAXB模块   JDK11。如果您打算在运行Eureka服务器时使用JDK 11,则可以   必须在您的POM或Gradle文件中包括这些依赖项。

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
</dependency>