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

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

问题描述

很抱歉,我需要分享每一行代码.

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

我已经使用通过码头服务器托管的Jersey创建了JAX-RS应用程序.但是我下面的代码将进入无限循环.码头不断发布消息并吞噬内存.仅当连接到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 -H "Content-Type: application/json" -d '{"username":"xyz","password":"xyz"}' http://localhost:8888/test
  2. 使用crome-poster发布查询不会导致此问题.仅在CURL上发生!
  3. CURL提示响应正常并安全退出,但码头保持循环.
  4. 我尝试了多种内容类型,但问题仍然存在.
  5. 问题是通过将码头从9.3.0.M1降级到9.2.0.M1来解决的
  1. curl query : curl -H "Content-Type: application/json" -d '{"username":"xyz","password":"xyz"}' http://localhost:8888/test
  2. Posting a query using crome-poster doesn't cause this issue. Only happens with CURL!
  3. CURL hets response OK and safely exits, but jetty keep up in loop.
  4. I tried multiple content-type but issue persists.
  5. Issue is resolved by downgrading jetty from 9.3.0.M1 to 9.2.0.M1

在无限循环中调试日志:

Debug Logs at infinite loop:

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.

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

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