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

DataBuffer Should Release Manually when Exception Thrown [SPR-15966] #20518

Closed
spring-projects-issues opened this issue Sep 15, 2017 · 0 comments
Closed
Assignees
Labels
in: web type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 15, 2017

Jason Yu opened SPR-15966 and commented

As this comment, I guess following implementation should manual release DataBuffer instance in catch block.

@Override
protected Mono<Void> renderInternal(Map<String, Object> renderAttributes,
		@Nullable MediaType contentType, ServerWebExchange exchange) {

	// Expose all standard FreeMarker hash models.
	SimpleHash freeMarkerModel = getTemplateModel(renderAttributes, exchange);
	if (logger.isDebugEnabled()) {
		logger.debug("Rendering FreeMarker template [" + getUrl() + "].");
	}

	Locale locale = LocaleContextHolder.getLocale(exchange.getLocaleContext());
	DataBuffer dataBuffer = exchange.getResponse().bufferFactory().allocateBuffer();
	try {
		Charset charset = getCharset(contentType);
		Writer writer = new OutputStreamWriter(dataBuffer.asOutputStream(), charset);
		getTemplate(locale).process(freeMarkerModel, writer);
	}
	catch (IOException ex) {
		String message = "Could not load FreeMarker template for URL [" + getUrl() + "]";
		return Mono.error(new IllegalStateException(message, ex));
	}
	catch (Throwable ex) {
		return Mono.error(ex);
	}
	return exchange.getResponse().writeWith(Flux.just(dataBuffer));
}

Affects: 5.0 RC4

Referenced from: commits 78434c8

@spring-projects-issues spring-projects-issues added type: bug in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0 GA milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web type: bug
Projects
None yet
Development

No branches or pull requests

2 participants