Skip to content

Returning Mono.empty causes controller to halt #518

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

Closed
bazusaladra opened this issue Nov 21, 2018 · 7 comments
Closed

Returning Mono.empty causes controller to halt #518

bazusaladra opened this issue Nov 21, 2018 · 7 comments
Labels
for/springframework This belongs to the Spring Framework project

Comments

@bazusaladra
Copy link

bazusaladra commented Nov 21, 2018

The following code used to work on SpringBoot 2.0.2

    @GetMapping(path = "search")
    public Mono<String> search(@RequestParam(value = "query") String query) {
        if (Objects.isNull(query) || query.isEmpty()) {
            return Mono.empty();
        }
        return Mono.just("result: " + query);
    }

After upgrading to SpringBoot 2.1.0 calling

String actualEmptyResult = restTemplate.getForObject("/api/search?query=", String.class);

causes any subsequent requests to this endpoint to be stalled.
Please check out test org.springtest.EmptyMonoFailureTest#testMono in repository https://github.com/bazusaladra/spring-mono-test.
SpringBoot team advised this issue may be related to Reactor Netty: spring-projects/spring-boot#15214

@rstoyanchev
Copy link
Contributor

This looks like the same issue as https://jira.spring.io/browse/SPR-17506. The fix on the WebFlux side, was to call response.setComplete() which completes without writing. Nevertheless there is a likely issue in Reactor Netty where writing with Mono.empty() never completes.

@violetagg violetagg added the type/bug A general bug label Nov 22, 2018
@violetagg violetagg added this to the 0.8.4.RELEASE milestone Nov 22, 2018
@bclozel
Copy link
Member

bclozel commented Dec 12, 2018

FYI I can't reproduce this issue anymore with Spring Boot 2.1.1.RELEASE, i.e. reactor netty 0.8.3.RELEASE (I can reproduce it with 2.1.0.RELEASE, i.e. 0.8.2.RELEASE).

@violetagg
Copy link
Member

violetagg commented Dec 12, 2018

@bclozel try with spring framework 5.1.2.RELEASE and Spring Boot 2.1.1.RELEASE

@bclozel
Copy link
Member

bclozel commented Dec 13, 2018

You're right @violetagg, this was fixed in spring-projects/spring-framework@abf9ce8a34

@rstoyanchev
Copy link
Contributor

This has been fixed in the Spring Framework. See https://jira.spring.io/browse/SPR-17609.

@giriganapathy
Copy link

Hello Team,

I am new to Flux, and i am streaming the file using Flux, however, my subsequent requests from browser is getting stuck, and here is my code:

@RequestMapping (value="/downloadReactive", produces=MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux downloadReactiveWay(ServerHttpRequest request, ServerHttpResponse response) throws Exception {

	Flux<DataBuffer> flux = null;		
	UrlResource urlResource = new UrlResource(FILE1);
	long totalSize = urlResource.contentLength();
	
	response.getHeaders().add("Content-Type", MediaType.APPLICATION_OCTET_STREAM_VALUE);
	response.getHeaders().add("Content-Disposition", "attachment; filename=\"app\"");		
	response.getHeaders().add("Content-Length", String.valueOf(totalSize));
	
	
	flux = DataBufferUtils.read(urlResource, new DefaultDataBufferFactory(), 1024);
	//https://github.com/spring-projects/spring-framework/commit/abf9ce8a34
	flux.switchIfEmpty(Flux.defer(()->{
		response.getHeaders().setContentLength(0);
		return response.setComplete().then(Mono.empty());
	}));
	
	
	return flux;		
}

POM.xml:

4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.5.RELEASE


com.reactive
download_server
0.0.1-SNAPSHOT
download_server
Demo project for Spring Boot

<properties>
	<java.version>1.8</java.version>
</properties>

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

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>io.projectreactor</groupId>
		<artifactId>reactor-test</artifactId>
		<scope>test</scope>
	</dependency>
</dependencies>

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

I am stuck here, It would be great, if someone shares the solution.
Thanks.

@giriganapathy
Copy link

My issue is exactly same (Spring FrameworkSPR-17506). Your quick reply is highly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for/springframework This belongs to the Spring Framework project
Projects
None yet
Development

No branches or pull requests

5 participants