-
Notifications
You must be signed in to change notification settings - Fork 129
Description
Since version 14 @ 40337f6, in an effort to enable developer-friendly DEBUG logs, trino-gateway truncates (and decodes) the body of proxy responses, but does not update the Content-Length header accordingly, which causes HTTP 500 errors when it tries to return the response back to the client:
HTTP ERROR 500 Insufficient content written 0 < 174
For example, with default configuration Trino's /v1/info responses are correctly proxied in their entirety:
$ curl 0.0.0.0:8085/v1/info -v
> GET /v1/info HTTP/1.1
> Host: 0.0.0.0:8085
>
< HTTP/1.1 200 OK
< ...
< Content-Length: 175
<
{"nodeId":"ffffffffffff","state":"ACTIVE","nodeVersion":{"version":"477"},"environment":"docker","coordinator":true,"coordinatorId":"xxxxx","starting":false,"uptime":"33.06s"}
If I add
proxyResponseConfiguration:
responseSize: 32B
to the config, I'd expect a malformed JSON response cut at 32 bytes, but the actual response is
$ curl 0.0.0.0:8085/v1/info -v
> GET /v1/info HTTP/1.1
> Host: 0.0.0.0:8085
>
< HTTP/1.1 500 Server Error
< ...
< Content-Length: 437
<
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 500 Insufficient content written 0 < 174</title>
</head>
<body>
<h2>HTTP ERROR 500 Insufficient content written 0 < 174</h2>
<table>
<tr><th>URI:</th><td>http://0.0.0.0:8085/v1/info</td></tr>
<tr><th>STATUS:</th><td>500</td></tr>
<tr><th>MESSAGE:</th><td>Insufficient content written 0 < 174</td></tr>
</table>
</body>
</html>
Note that this setting is different from proxy.http-client.max-content-length, which raises a standard "Buffering capacity exceeded" error when proxy response exceeds the limit. This bug is only reproducible when response body is shorter than or equal to proxy.http-client.max-content-length (16MB by default), but longer than proxyResponseConfiguration.responseSize (32MB by default). That is, every time truncation actually happens.
See also #680