restlet / restlet-framework-java

The first REST API framework for Java
https://restlet.talend.com
646 stars 284 forks source link

204 responses close keep-alive connections in Restlet 2.4 #1377

Closed jbeckerOSI closed 3 years ago

jbeckerOSI commented 3 years ago

In Restlet 2.4.3 204 responses appear to break/close keep-alive connections.

I have a single Restlet server running behind an nginx proxy. When I configure nginx to use an upstream keepalive pool (http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive) requests made to nginx periodically fail with a 502. The following nginx error accompanies the 502s in error.log: 2020/10/26 15:18:27 [error] 466640#185532: *4232 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "POST /local/notify/v1/topics HTTP/1.1", upstream: "http://127.0.0.1:8190/local/notify/v1/topics", host: "127.0.0.1:81"

I have multiple resources/endpoints in my Restlet server. Some of them return 200 responses with payloads, others return 204 responses with no payload. Periodically requests to the endpoints via nginx WITH a response payload will fail. This is most noticable if I spam requests both the 200 and 204 responding endpoints at the same time.

If I change the endpoints that return 204s to instead return something trivial, like 200/"SUCCESS" then the 502 errors no longer occur.

This behavior does not occur in Restlet 2.3.12.

cyberquarks commented 3 years ago

@jbeckerOSI

Have you tried setting in NGINX, Connection "" to your server block?

jbeckerOSI commented 3 years ago

Yes. The problem ended up being due to a missing restlet library on the classpath. When upgrading from 2.3 to 2.4 we forgot to include org.restlet.ext.platform.jar.

Once we got that library correctly added things behaved as expected.