带有 curl 后查询的 Jetty+Jersey 无限循环 [英] Jetty+Jersey infinite loop with curl post query

查看:34
本文介绍了带有 curl 后查询的 Jetty+Jersey 无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,帖子太长了,我需要分享每一行代码.

Sorry for the long post, I need to share every line of code.

我已经创建了一个 JAX-RS 应用程序,使用托管在码头服务器上的 Jersey.但是,我的以下代码将用于无限循环.Jetty 不断发布消息并吞噬记忆.这仅在连接到 CURL 客户端时才会发生.

I have created a JAX-RS application using Jersey hosted over jetty server. My following code however is going for infinite loop. Jetty keep posting messages and eats away the memory. This happens only when connected to CURL client.

Jetty-服务器:

public class HttpServer {
  public static void main(String[] args) throws Exception
  {
     //Set JAX-RS
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.setContextPath("/");
    Server server = new Server(8888);
    server.setHandler(context);
    ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
    jerseyServlet.setInitOrder(0);
    // Tells the Jersey Servlet which REST service/class to load.
    jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",TestResource.class.getCanonicalName());

    try {
      server.start();
         while(true){
      server.join();
      logger.log(Level.WARNING,"HTTP Server Killed. Restarting");
      server.start();
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      logger.log(Level.SEVERE,"EXCPETION DETECTED:" +e.hashCode());
    }

  }


}

Jax-RS 资源

@Path("/test")

public class TestResource
{

  @POST
  @Consumes("application/json")
  @Produces("text/html")
  public Response fillData(String json)
  {
    System.out.println(json);

    return Response.status(200).entity("Successfully updated").build();

  }

}

注意事项:

  1. curl 查询:curl -H "Content-Type: application/json" -d '{"username":"xyz","password":"xyz"}' http://localhost:8888/测试
  2. 使用 crome-poster 发布查询不会导致此问题.只有 CURL 才会发生!
  3. CURL hets 响应正常并安全退出,但码头保持循环.
  4. 我尝试了多种内容类型,但问题仍然存在.
  5. 问题已通过将码头从 9.3.0.M1 降级到 9.2.0.M1 解决

无限循环调试日志:

11:21:40.760 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG org.eclipse.jetty.io.SelectorManager - Selector loop woken up from select, 0/1 selected
11:21:40.761 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG org.eclipse.jetty.io.SelectorManager - Running change org.eclipse.jetty.io.SelectChannelEndPoint$1@54ddf089
11:21:40.761 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG o.e.jetty.io.SelectChannelEndPoint - Updating key, state UPDATE_PENDING for SelectChannelEndPoint@55446de5{/127.0.0.1:55160<->8888,Open,ISHUT,out,R,-,30000,HttpConnection}{io=1,kio=0,kro=1}
11:21:40.761 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG o.e.jetty.io.SelectChannelEndPoint - Key interests update 0 -> 1 for SelectChannelEndPoint@55446de5{/127.0.0.1:55160<->8888,Open,ISHUT,out,R,-,30000,HttpConnection}{io=1,kio=0,kro=1}
11:21:40.761 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG org.eclipse.jetty.io.SelectorManager - Selector loop waiting on select
11:21:40.761 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG org.eclipse.jetty.io.SelectorManager - Selector loop woken up from select, 1/1 selected
11:21:40.761 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG o.e.jetty.io.SelectChannelEndPoint - Processing, state UPDATED for SelectChannelEndPoint@55446de5{/127.0.0.1:55160<->8888,Open,ISHUT,out,R,-,30000,HttpConnection}{io=1,kio=1,kro=1}
11:21:40.761 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG o.e.jetty.io.SelectChannelEndPoint - onSelected 1->0 for SelectChannelEndPoint@55446de5{/127.0.0.1:55160<->8888,Open,ISHUT,out,R,-,30000,HttpConnection}{io=0,kio=1,kro=1}
11:21:40.761 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG o.e.jetty.io.AbstractConnection - FILL_INTERESTED-->FILLING HttpConnection@21c7226e{FILLING}
11:21:40.762 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG o.e.jetty.io.SelectChannelEndPoint - Updating key, state UPDATE_PENDING for SelectChannelEndPoint@55446de5{/127.0.0.1:55160<->8888,Open,ISHUT,out,-,-,30000,HttpConnection}{io=0,kio=1,kro=1}
11:21:40.762 [qtp1669854350-19] DEBUG o.e.jetty.server.HttpConnection - HttpConnection@21c7226e{FILLING} onFillable HttpChannelState@36dadde6{s=IDLE i=true a=null}
11:21:40.762 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG o.e.jetty.io.SelectChannelEndPoint - Key interests update 1 -> 0 for SelectChannelEndPoint@55446de5{/127.0.0.1:55160<->8888,Open,ISHUT,out,-,-,30000,HttpConnection}{io=0,kio=1,kro=1}
11:21:40.762 [qtp1669854350-19] DEBUG org.eclipse.jetty.http.HttpParser - atEOF HttpParser{s=CLOSED,0 of -1}
11:21:40.762 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG org.eclipse.jetty.io.SelectorManager - Selector loop waiting on select
11:21:40.762 [qtp1669854350-19] DEBUG org.eclipse.jetty.http.HttpParser - parseNext s=CLOSED HeapByteBuffer@1[p=0,l=0,c=0,r=0]={<<<>>>}
11:21:40.762 [qtp1669854350-19] DEBUG o.e.jetty.io.AbstractConnection - fillInterested HttpConnection@21c7226e{FILLING}
11:21:40.762 [qtp1669854350-19] DEBUG o.e.jetty.io.AbstractConnection - FILLING-->FILLING_FILL_INTERESTED HttpConnection@21c7226e{FILLING_FILL_INTERESTED}
11:21:40.762 [qtp1669854350-19] DEBUG o.e.jetty.io.AbstractConnection - FILLING_FILL_INTERESTED-->FILL_INTERESTED HttpConnection@21c7226e{FILL_INTERESTED}
11:21:40.762 [qtp1669854350-19] DEBUG o.e.jetty.io.SelectChannelEndPoint - Changing interests in state UPDATED for SelectChannelEndPoint@55446de5{/127.0.0.1:55160<->8888,Open,ISHUT,out,R,-,30000,HttpConnection}{io=0,kio=0,kro=1}
11:21:40.762 [qtp1669854350-19] DEBUG o.e.jetty.io.SelectChannelEndPoint - changeInterests s=UPDATED 0->1 for SelectChannelEndPoint@55446de5{/127.0.0.1:55160<->8888,Open,ISHUT,out,R,-,30000,HttpConnection}{io=0,kio=0,kro=1}
11:21:40.762 [qtp1669854350-19] DEBUG org.eclipse.jetty.io.SelectorManager - Queued change org.eclipse.jetty.io.SelectChannelEndPoint$1@54ddf089
11:21:40.762 [qtp1669854350-14-selector-ServerConnectorManager@62dfb098/0] DEBUG org.eclipse.jetty.io.SelectorManager - Selector loop woken

我无法从日志中获得太多意义,但可以肯定的是,即使客户端已安全退出,Jetty 也不会关闭连接.我尝试在码头设置超时,但没有用.

I can't make much sense out of the logs but one thing is certain that Jetty is not closing connection even when the client has safely exited. I tried setting timeout at jetty, but of no use.

代码是否有任何问题,或者最新版本的 Jetty 似乎存在一些错误.请注意,我在开发 JAVA EE 应用程序方面完全天真.如果这是一个错误,我会在 Jetty 论坛中报告.

Is there any issue with the code, or there seems to be some bug with newest version of Jetty. Note that I am totally naive in developing JAVA EE Applications. If that is a bug, I will report in Jetty Forums.

推荐答案

这个问题已经被识别为 https://bugs.eclipse.org/bugs/show_bug.cgi?id=452465 并且它已经在 master 分支中修复,并将成为 Jetty 的一部分9.3.0.M2.

This issue has already been identified as https://bugs.eclipse.org/bugs/show_bug.cgi?id=452465 and it's already fixed in the master branch, and will be part of Jetty 9.3.0.M2.

这篇关于带有 curl 后查询的 Jetty+Jersey 无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆