question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

spring-mvc:chunked responses with status 500 are damaged

See original GitHub issue

version: Spring Boot 2.2.5.RELEASE environment: java: Java™ SE Runtime Environment (build 1.8.0_172-b11) os: mac. os and linux contrainer: tomcat

the bug is related to here I have worked for days to reproduced the problem

https://github.com/spring-cloud/spring-cloud-gateway/issues/1600

when I create a controller and just return ResponseEntity there will be return

curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding

my code

@RequestMapping("api/v1")
@RestController
public class ProxyController {

    @GetMapping("/proxy500")
    public ResponseEntity<?> proxy500(ProxyExchange<byte[]> proxy) {
        MultiValueMap<String, String> multiValueMap = new HttpHeaders();
        multiValueMap.put("Transfer-Encoding", Collections.singletonList("chunked"));
        multiValueMap.put("Connection", Collections.singletonList("close"));
        return new ResponseEntity<>("{", multiValueMap, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

detail

curl http://localhost:8080/api/v1/proxy500 -vvv
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /api/v1/proxy500 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 500 
< Transfer-Encoding: chunked
< Connection: close
< Content-Type: text/plain;charset=UTF-8
< Date: Sat, 14 Mar 2020 17:13:04 GMT
< 
* Illegal or missing hexadecimal sequence in chunked-encoding
* stopped the pause stream!
* Closing connection 0
curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding

reason maybe here , the header info send flush until message send

org.springframework.http.converter.StringHttpMessageConverter#writeInternal

@Override
protected void writeInternal(String str, HttpOutputMessage outputMessage) throws IOException {
    HttpHeaders headers = outputMessage.getHeaders();
    if (this.writeAcceptCharset && headers.get(HttpHeaders.ACCEPT_CHARSET) == null) {
        headers.setAcceptCharset(getAcceptedCharsets());
    }
    Charset charset = getContentTypeCharset(headers.getContentType());
    StreamUtils.copy(str, charset, outputMessage.getBody());
}

this my source code

https://github.com/taojiaenx/spring-chunk-bug.git

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
taojiaenxcommented, Mar 18, 2020

@rstoyanchev thx, I am will keep working on it

0reactions
jaggerwangcommented, Aug 17, 2022

Same problem! I think it should be solved in application framework not in servlet container.

Read more comments on GitHub >

github_iconTop Results From Across the Web

gateway-mvc: chunked responses with status 500 are damaged
When using default tomcat servlet container, 500 errors that are produced in the downstream service are not correctly transfered to the client. Actual...
Read more >
ERR_INCOMPLETE_CHUNKED...
I faced this ERR_INCOMPLETE_CHUNKED_ENCODING issue specifically with POST requests handled in the context of a proxy: requests were initiated ...
Read more >
Error handling in REST and Spring Boot | Nullbeans
In this post, we will discuss how to handle common errors (such as HTTP 404 Not found) and exceptions in your REST API...
Read more >
"too many transfer encodings" 502 chunked response errors ...
The error described in this KB occurs if any response from an application has multiple transfer-encoding headers, either directly adding or a ...
Read more >
Spring4Shell: Zero-Day Vulnerability in Spring Framework
The vulnerability affects SpringMVC and Spring WebFlux applications ... web application paths in order to trigger an HTTP 500 response, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found