Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpClient blocked after a failed request, error "unexpected message type: DefaultHttpRequest" #18

Closed
fayndee opened this issue Dec 19, 2016 · 2 comments
Labels
type/bug A general bug
Milestone

Comments

@fayndee
Copy link

fayndee commented Dec 19, 2016

Version:
spring-boot-starter-web-reactive:0.1.0.BUILD-SNAPSHOT => reactor-netty-0.6.0.BUILD-20161219.135933-150

We used spring-web-reactive in our application since a while and it worked fine. Today, we got exception in our test client and the process is blocked somehow due to this error:

2016-12-19 18:49:24,359 [reactor-http-nio-1] ERROR reactor.ipc.netty.channel.ChannelOperations - [HttpClient] Error processing connection. Requesting close the channel
io.netty.handler.codec.EncoderException: java.lang.IllegalStateException: unexpected message type: DefaultHttpRequest
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:106)
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:749)
	at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:812)
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:825)
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:805)
	at reactor.ipc.netty.channel.ChannelOperationsHandler.doWrite(ChannelOperationsHandler.java:267)
	at reactor.ipc.netty.channel.ChannelOperationsHandler.drain(ChannelOperationsHandler.java:368)
	at reactor.ipc.netty.channel.ChannelOperationsHandler.flush(ChannelOperationsHandler.java:150)
	at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:787)
	at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:813)
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:825)
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:805)
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:842)
	at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1032)
	at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:296)
	at reactor.ipc.netty.http.HttpOperations.lambda$sendHeaders$0(HttpOperations.java:98)
	at reactor.ipc.netty.FutureMono$DeferredFutureMono.subscribe(FutureMono.java:114)
	at reactor.core.publisher.FluxConcatIterable$ConcatIterableSubscriber.onComplete(FluxConcatIterable.java:152)
	at reactor.core.publisher.FluxConcatIterable.subscribe(FluxConcatIterable.java:69)
	at reactor.core.publisher.MonoNext.subscribe(MonoNext.java:41)
	at reactor.ipc.netty.channel.ChannelOperations.applyHandler(ChannelOperations.java:421)
	at reactor.ipc.netty.http.client.HttpClientOperations.onChannelActive(HttpClientOperations.java:452)
	at reactor.ipc.netty.channel.PooledClientContextHandler.connectOrAcquire(PooledClientContextHandler.java:171)
	at reactor.ipc.netty.channel.PooledClientContextHandler.lambda$operationComplete$0(PooledClientContextHandler.java:118)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:454)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: unexpected message type: DefaultHttpRequest
	at io.netty.handler.codec.http.HttpObjectEncoder.encode(HttpObjectEncoder.java:69)
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:88)

After this error, the process is hanging forever. To reproduce this, one could setup a spring boot project using the version mentioned above and with the follow classes:

Application.java

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        new SpringApplication().run(args);
    }
}
AnyController.java

@Controller
@RequestMapping("/any")
public class AnyController {
    @RequestMapping(value = "/thing", method = RequestMethod.HEAD)
    public Mono<ResponseEntity<Void>> testAny() {
        return Mono.just(ResponseEntity.notFound().build());
    }
}
AnyControllerTest.java

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class AnyControllerTest {
    @LocalServerPort
    int port;
    String url = "http://localhost:{port}/any/thing";
    WebClient webClient = WebClient.create(new ReactorClientHttpConnector());
    @Test
    public void aTest() {
        Mono<ClientResponse> response = webClient.exchange(ClientRequest.HEAD(url, port).build());
        assert response.block().statusCode() == HttpStatus.NOT_FOUND;
    }
    @Test
    public void anotherTest() {
        Mono<ClientResponse> response = webClient.exchange(ClientRequest.HEAD(url, port).build());
        assert response.block().statusCode() == HttpStatus.NOT_FOUND;
    }
}

When one runs the test, the first test case will succeed without any problem, however the second one will be simply blocked and hangs forever....

@fayndee
Copy link
Author

fayndee commented Dec 20, 2016

FYI, when I switch back to reactor-netty-0.6.0.BUILD-20161216.012745-138, the problem disappears.

@smaldini
Copy link
Contributor

Should be fixed in latest snapshot we refined some of this before 0.6.0.RELEASE which should be out today

@smaldini smaldini added this to the 0.6.0.RELEASE milestone Dec 23, 2016
@smaldini smaldini added the type/bug A general bug label Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants