gpt4 book ai didi

jersey - Jetty+Jersey 无限循环与 curl post 查询

转载 作者:行者123 更新时间:2023-12-04 02:27:32 24 4
gpt4 key购买 nike

抱歉发了这么长的帖子,我需要分享每一行代码。

我使用托管在 jetty 服务器上的 Jersey 创建了一个 JAX-RS 应用程序。然而,我的以下代码将无限循环。 Jetty 不断发布消息并消耗内存。这仅在连接到 CURL 客户端时发生。

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 响应正常并安全退出,但 jetty 保持循环。
  4. 我尝试了多种内容类型,但问题仍然存在。
  5. 问题已通过将 jetty 从 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 也不会关闭连接。我尝试在 jetty 设置超时,但没有用。

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

最佳答案

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

关于jersey - Jetty+Jersey 无限循环与 curl post 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27055440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com