splincodewd
@splincodewd
Developer

Почему в одном из множества запросов я получаю статус ответа HTTP 502 Bad Gateway?

Я написал простой класс ProxyServlet extends org.eclipse.jetty.proxy.ProxyServlet.Transparent и использовал его вместе с org.eclipse.jetty.server.Server.

Когда я монотонно посылаю один и тот же запрос, иногда получаю ошибку.

Я попробовал причал версий: 9.4.3.v20170317 и 9.3.15.v20161220.

Журнал успешного запроса:

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


Журнал запроса ошибки:
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: HttpConnectionOverHTTP@6e5c3dff(l:/127.0.0.1:47382 <-> r:localhost/127.0.0.1:8888,closed=false)=>HttpChannelOverHTTP@b1621c8(exchange=HttpExchange@4556a5a3 req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@1f66c7cc(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@3c63c99c{s=START}],recv=HttpReceiverOverHTTP@641b7b9(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]<-SocketChannelEndPoint@764a716f{localhost/127.0.0.1:8888<->/127.0.0.1:47382,ISHUT,fill=-,flush=-,to=5/30000}{io=0/0,kio=0,kro=1}->HttpConnectionOverHTTP@6e5c3dff(l:/127.0.0.1:47382 <-> r:localhost/127.0.0.1:8888,closed=false)=>HttpChannelOverHTTP@b1621c8(exchange=HttpExchange@4556a5a3 req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@1f66c7cc(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@3c63c99c{s=START}],recv=HttpReceiverOverHTTP@641b7b9(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


Я не знаю почему, но иногда связь между прокси и целевым сервером закрывается. Событие запроса не достигает сервлета на сервере. Вот код сервера:

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();


Есть информация со сниффинга, более подробно тут:
stackoverflow.com/questions/43095360/in-1-of-a-lot...

в плохом пакете было найдено отличие (на ошибку 502)
[Window size scaling factor: -1 (unknown)]

Не знаю, как с этим может быть связано. Тестирую на Linux, на Windows (все работает).
  • Вопрос задан
  • 560 просмотров
Пригласить эксперта
Ответы на вопрос 1
dimonchik2013
@dimonchik2013
non progredi est regredi
а в чем вопрос?

ну не ответил по таймауту, и что ? мир не совершенен, джава тем болеее
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы