[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 762
  • Last Modified:

Problem with Jetty: java.lang.IllegalStateException: Commited and java.lang.IllegalStateException: Not EDITABLE exceptions under load

I have the following JSP code:
<%@ page buffer="128kb" errorPage="/jsp/Error.jsp" isThreadSafe="true"%>
...
<%
    response.setContentType("text/html; charset="+Config.getInstance().getEncoding());
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0
    response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
...
    String lastPath = request.getParameter("last_path");
    if (lastPath != null) {
        if(URLDecoder.decode(lastPath, "UTF-8").indexOf("TSFrame.jsp?ID=") != -1) {
            redirect(lastPath);
            return;
        } else if(URLDecoder.decode(lastPath, "UTF-8").indexOf("TSFrame.jsp") == -1){
            session.setAttribute("MAIN_FRAME_GO_TO", lastPath);
            redirect(request.getContextPath() + "/jsp/TSFrame.jsp");
            return;
        }        
    }
    redirect(request.getContextPath() + "/jsp/SwitchAction.jsp");

%>

Under low load all works fine, but under high load I got following exception:
java.lang.IllegalStateException: Commited
      at org.mortbay.http.HttpResponse.sendRedirect(HttpResponse.java:448)
      at
org.mortbay.jetty.servlet.ServletHttpResponse.sendRedirect(ServletHttp
Response.java:432)
      at jsp.login.LoginAction_jsp.redirect(LoginAction_jsp.java:43)
      at jsp.login.LoginAction_jsp._jspService(LoginAction_jsp.java:173)
      at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

Also I got the following under load:
16:49:26.234 WARN!! GET
/TrackStudio/jsp/task/subtasks/Subtasks.jsp?ID=651 HTTP/1.1
java.lang.IllegalStateException: Not EDITABLE
      at org.mortbay.http.HttpMessage.setVersion(HttpMessage.java:542)
      at
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:913)
      at org.mortbay.http.HttpConnection.handle(HttpConnection.java:807)
      at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:2
18)

How this can happend ? Seems like we don't send any content before redirect and have enough buffer.

0
maximkr
Asked:
maximkr
  • 6
  • 4
1 Solution
 
petmagdyCommented:
please try to increase the jetty Java memory process like this:

java -Xms256m -Xmx512m
0
 
maximkrAuthor Commented:
Don't help. I don't think that problem is the load itself, the bug occurs only on this page when several users login the same time. Just test it: 5 users login the same time and  4 of them got this exception. It have no chance to eat all memory/threads/etc

The second (Not EDITABLE) exception also occurs only on the specific page.
0
 
maximkrAuthor Commented:
Another strange exception under load:

java.lang.IllegalStateException: BAD is not EDITABLE
      at org.mortbay.http.HttpResponse.writeHeader(HttpResponse.java:248)
      at org.mortbay.http.BufferedOutputStream.writeHeader(BufferedOutputStream.java:105)
      at org.mortbay.http.HttpOutputStream.writeHeader(HttpOutputStream.java:420)
      at org.mortbay.http.HttpConnection.commit(HttpConnection.java:717)
      at org.mortbay.http.HttpConnection.outputNotify(HttpConnection.java:530)
      at org.mortbay.http.HttpOutputStream.notify(HttpOutputStream.java:556)
      at org.mortbay.http.HttpOutputStream.outputNotify(HttpOutputStream.java:541)
      at org.mortbay.http.BufferedOutputStream.flush(BufferedOutputStream.java:178)
      at org.mortbay.http.ChunkingOutputStream.flush(ChunkingOutputStream.java:67)
      at org.mortbay.http.HttpOutputStream.flush(HttpOutputStream.java:486)
      at org.mortbay.http.HttpResponse.commit(HttpResponse.java:489)
      at org.mortbay.http.HttpResponse.sendRedirect(HttpResponse.java:451)
      at org.mortbay.jetty.servlet.ServletHttpResponse.sendRedirect(ServletHttpResponse.java:432)
      at jsp.SwitchAction_jsp.redirect(SwitchAction_jsp.java:69)
      at jsp.SwitchAction_jsp._jspService(SwitchAction_jsp.java:213)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
maximkrAuthor Commented:
Just tried with Tomcat 4 - the same problems:

java.lang.IllegalStateException
        at org.apache.catalina.connector.HttpResponseFacade.sendRedirect(HttpResponseFacade.java:173)
        at org.apache.jsp.LoginAction$jsp.redirect(LoginAction$jsp.java:56)
        at org.apache.jsp.LoginAction$jsp._jspService(LoginAction$jsp.java:216)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
0
 
petmagdyCommented:
why r u using redirect, r u redirecting to a Web component outside ur Tomcat or jetty?

please explain what do loginaction do
0
 
maximkrAuthor Commented:
No, LoginAction just check that username/password is correct, update cookies (set new password to cookies) and redirect to page that actually show data. I found the following topic:
http://www.jguru.com/faq/view.jsp?EID=501393

It seems that we got this problem because we can't set cookie and redirect in the same servlet. But I don't understand how to handle this correctly - where we should set up cookies ?
0
 
petmagdyCommented:
is this struts action, or normal servlet?
0
 
maximkrAuthor Commented:
Its JSP with
<%
at the begin and
%>
at the end.

Please see code sample in the very first message
0
 
petmagdyCommented:
sorry i missed to look at the begining of the thread

first move the first 4 lines of:

   response.setContentType("text/html; charset="+Config.getInstance().getEncoding());
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0
    response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

to the redirected jsps

second instead of sendRedirect use forward like this:

    getServletConfig().getServletContext().getRequestDispatcher("SwitchAction.jsp").forward(request,response);

the jsp provided is relative path, assuming that all ur jsp r in the same directory, please try this and tell me the result




0
 
maximkrAuthor Commented:
Got some problems with paths (it can't find SwitchAction.jsp, will investigate tomorrow) and the following warning:

Invalid length: Content-Length=1304 written=1410 for http://localhost:8888/TrackStudio/jsp/login/LoginAction.jsp

Seems like some headers was sent before.

But I still have 2 major questions:
1) Why buffers don't work ? I expect that 128 k should be enough to store all headers before we finish page generation.
2) In LoginAction.jsp we also setup cookies. As I understand, I can't setup cookies in servlet that forward or redirect control. How we should to setup it ?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now