M
M
Maxim Ivanov2017-04-25 14:20:28
Java
Maxim Ivanov, 2017-04-25 14:20:28

Why am I getting an HTTP 502 Bad Gateway response status on one of my many requests?

I wrote a simple ProxyServlet extends org.eclipse.jetty.proxy.ProxyServlet.Transparent class and used it along with org.eclipse.jetty.server.Server.
When I monotonously send the same request, sometimes I get an error.
I tried jetty versions: 9.4.3.v20170317 and 9.3.15.v20161220.
Success log:

2017-03-29 16:11:01 [qtp922145372-30] DEBUG 65e620b0:71 - 886655093 rewriting: http://localhost:8282/api/state-get?hash=1490793061907 -> http://localhost:8888/api/state-get?hash=1490793061907
2017-03-29 16:11:01 [qtp922145372-30] DEBUG 65e620b0:539 - 886655093 proxying to upstream:
GET /api/state-get?hash=1490793061907 HTTP/1.1
Cookie: JSESSIONID=node01lgbitpmvb4lg19wqy2t1vbhhj0.node0
Cache-Control: no-cache
Accept: application/json, text/plain, /
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36
Referer: http://localhost:8282/
Host: localhost:8282
Pragma: no-cache
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8,ru;q=0.6
auth-user: aW50XGFkbWlu
auth-roles: 0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YA=

HttpRequest[GET /api/state-get HTTP/1.1]@f5d34a2

2017-03-29 16:11:01 [ProxyServlet-65e620b0-37] DEBUG 65e620b0:599 - 886655093 proxying to downstream:
HttpResponse[HTTP/1.1 200 OK]@66b83d74
Date: Wed, 29 Mar 2017 13:11:01 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 67
Server: Jetty(9.4.3.v20170317)

2017-03-29 16:11:01 [ProxyServlet-65e620b0-37] DEBUG 65e620b0:138 - 886655093 proxying content to downstream: 67 bytes
2017-03-29 16:11:01 [ProxyServlet-65e620b0-37] DEBUG 65e620b0:618 - 886655093 proxying successful
2017-03-29 16:11:01 [ProxyServlet-65e620b0-37] DEBUG 65e620b0:240 - 886655093 proxying complete

Error request log:
2017-03-29 16:10:31 [qtp922145372-30] DEBUG 65e620b0:71 - 424608794 rewriting: http://localhost:8282/api/state-get?hash=1490793031907 -> http://localhost:8888/api/state-get?hash=1490793031907
2017-03-29 16:10:31 [qtp922145372-30] DEBUG 65e620b0:539 - 424608794 proxying to upstream:
GET /api/state-get?hash=1490793031907 HTTP/1.1
Cookie: JSESSIONID=node01lgbitpmvb4lg19wqy2t1vbhhj0.node0
Cache-Control: no-cache
Accept: application/json, text/plain, /
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36
Referer: http://localhost:8282/
Host: localhost:8282
Pragma: no-cache
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8,ru;q=0.6
auth-user: aW50XGFkbWlu
auth-roles: 0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YA=

HttpRequest[GET /api/state-get HTTP/1.1]@34e1eb9e

2017-03-29 16:10:31 [ProxyServlet-65e620b0-38] DEBUG 65e620b0:627 - 424608794 proxying failed
java.io.EOFException: [email protected](l:/127.0.0.1:47382 <-> r:localhost/127.0.0.1:8888,closed=false)=>[email protected]([email protected] req=TERMINATED/[email protected] res=PENDING/[email protected])[[email protected](req=QUEUED,snd=COMPLETED,failure=null)[[email protected]{s=START}],[email protected](rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]<[email protected]{localhost/127.0.0.1:8888<->/127.0.0.1:47382,ISHUT,fill=-,flush=-,to=5/30000}{io=0/0,kio=0,kro=1}->[email protected](l:/127.0.0.1:47382 <-> r:localhost/127.0.0.1:8888,closed=false)=>[email protected]([email protected] req=TERMINATED/[email protected] res=PENDING/[email protected])[[email protected](req=QUEUED,snd=COMPLETED,failure=null)[[email protected]{s=START}],[email protected](rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]
 at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.earlyEOF(HttpReceiverOverHTTP.java:310) [jetty-client-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1418) [jetty-http-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.shutdown(HttpReceiverOverHTTP.java:196) [jetty-client-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:143) [jetty-client-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:70) [jetty-client-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:130) [jetty-client-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:116) [jetty-client-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) [jetty-io-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110) [jetty-io-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) [jetty-io-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:122) [jetty-util-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.util.thread.strategy.ExecutingExecutionStrategy.invoke(ExecutingExecutionStrategy.java:58) [jetty-util-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:201) [jetty-util-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:133) [jetty-util-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672) [jetty-util-9.4.3.v20170317.jar:9.4.3.v20170317]
 at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590) [jetty-util-9.4.3.v20170317.jar:9.4.3.v20170317]
 at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
2017-03-29 16:10:31 [ProxyServlet-65e620b0-38] DEBUG 65e620b0:240 - 424608794 proxying complete

I don't know why, but sometimes the connection between the proxy and the target server is closed. The request event does not reach the servlet on the server. Here is the server code:
server = new Server(port);

            final String webDir = isNotBlank(webappPath) ? webappPath : new ClassPathResource(WEBAPP_DIR_NAME).getURI().toString();
            final WebAppContext webAppContext = new WebAppContext(webDir, "/" + context);

            webAppContext.setInitParameter("org.eclipse.jetty.servlet.Default.gzip", "true");
            webAppContext.setInitParameter("org.eclipse.jetty.servlet.Default.cacheControl", "max-age=3600,public");

            final ServletHolder apiServletHolder = new ServletHolder(new ApiServlet(getPluginResponseListener(), getPluginListener(), getPluginInfoRequestListener()));
            final String apiServletMapping = "/" + ApiServlet.SERVLET_PATH + "/*";

            webAppContext.addServlet(apiServletHolder, apiServletMapping);
            webAppContext.setMaxFormContentSize(10 * 1024 * 1024);
            webAppContext.setErrorHandler(getErrorHandler());

            server.setHandler(webAppContext);

            server.start();

There is information from sniffing, more details here:
stackoverflow.com/questions/43095360/in-1-of-a-lot...
a difference was found in a bad package (for error 502)
[Window size scaling factor: -1 (unknown )]
I do not know how this can be connected. I test on Linux, on Windows (everything works).

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
Dimonchik, 2017-04-25
@dimonchik2013

what is the question?
well, did not answer by timeout, so what? the world is not perfect, especially Java

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question