spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.34k stars 40.5k forks source link

Using webflux occured IOException #13035

Closed boy1064910 closed 6 years ago

boy1064910 commented 6 years ago

Exception but is not error. RestTemplate can get a right response.but the called occured this exception.

java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
    at sun.nio.ch.SocketDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
    at sun.nio.ch.IOUtil.read(IOUtil.java:192)
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
    at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1108)
    at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:345)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
    at java.lang.Thread.run(Thread.java:748)

I use restTemplate and @LoadBalanaced to call one api url which published by webflux .

The Called code

@GetMapping("/testMono")
    public Mono<BaseResult> testMono(){
        BaseResult baseResult = new BaseResult();
        return Mono.just(baseResult);
    }
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
    </parent>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>            

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.M9</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>    

The caller code

@GetMapping("/testMono")
    public ResponseModel testMono(@PathVariable String dataSourceCode) {
        String url = “http://ga/testMono”;//ga is a service id in eureka
        ResponseEntity<BaseResult> responseEntity = restTemplate.getForEntity(url, BaseResult.class);
        logger.info(JsonUtil.entity2Json(responseEntity.getBody()));
        return new ResponseModel();
    } 

@Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
    </parent>

<dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.M9</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
        </dependency>
bclozel commented 6 years ago

Courtesy of Google Translate: java.io.IOException: The software in your host has stopped an established connection.

I don't see anything obvious here, besides the fact that you're using Spring Cloud Finchley.M9 with Spring Boot 2.0.1 (Finchley.M9 is only officially compatible with Spring Boot 2.0.0). Also, your example has a lot of moving pieces, involving several servers, a registry, a client loadbalancer.

Could you work on creating a smaller sample application, removing pieces to narrow down the issue? Does this still happen if you remove Spring Cloud from the equation and simply use a RestTemplate on it?

Please share a sample application (something we can unzip/git clone and run) so we can take a look at it. Thanks!

spring-projects-issues commented 6 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 6 years ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.