1. Sebastian Sebastian
  2. scm-manager
  3. Issues

Issues

Issue #481 resolved

SCM-Manager sets contentLength -1

heppoko act
created an issue

Many thanks for SCM-Manager.
Sorry for my broken English.

My enviorment:
CnetOS 6.4
jetty 9.0.6.v20130930
SCM-Manager 1.34 (war)
mercurial 2.7.2

I have got an error when I execute a command:

hg clone http://myserver/scm/hg/myrepository

Error log in $JETTY_HOME/logs/2013_11_02.stderrout.log:

01:37:44.713 [qtp1485904799-14] ERROR sonia.scm.web.HgCGIExceptionHandler - not able to handle mercurial request
java.lang.IllegalArgumentException: setContentLength(-1) when already written 0
        at org.eclipse.jetty.server.Response.setContentLength(Response.java:763) ~[na:na]
        at sonia.scm.web.cgi.DefaultCGIExecutor.parseHeaders(DefaultCGIExecutor.java:428) ~[classes/:na]
        at sonia.scm.web.cgi.DefaultCGIExecutor.execute(DefaultCGIExecutor.java:401) ~[classes/:na]
        at sonia.scm.web.cgi.DefaultCGIExecutor.execute(DefaultCGIExecutor.java:191) ~[classes/:na]
        at sonia.scm.web.HgCGIServlet.process(HgCGIServlet.java:285) [scm-hg-plugin-1.34.jar:na]
        at sonia.scm.web.HgCGIServlet.handleRequest(HgCGIServlet.java:203) [scm-hg-plugin-1.34.jar:na]
        at sonia.scm.web.HgCGIServlet.service(HgCGIServlet.java:177) [scm-hg-plugin-1.34.jar:na]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) [servlet-api-3.0.jar:na]
        at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263) [guice-servlet-3.0.jar:na]
        at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178) [guice-servlet-3.0.jar:na]
        at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91) [guice-servlet-3.0.jar:na]

(snip)

org.eclipse.jetty.server.Response (version: 9.0.6.v20130930)

752     @Override
753     public void setContentLength(int len)
754     {
755         // Protect from setting after committed as default handling
756         // of a servlet HEAD request ALWAYS sets _content length, even
757         // if the getHandling committed the response!
758         if (isCommitted() || isIncluding())
759             return;
760 
761         long written = _out.getWritten();
762         if (written > len)
763             throw new IllegalArgumentException("setContentLength(" + len + ") when already written " + written);
764 
765         _contentLength = len;
766         _fields.putLongField(HttpHeader.CONTENT_LENGTH.toString(), len);
767 
768         if (_contentLength > 0)
769         {
770             if (isAllContentWritten(written))
771             {
772                 try
773                 {
774                     closeOutput();
775                 }
776                 catch(IOException e)
777                 {
778                     throw new RuntimeIOException(e);
779                 }
780             }
781         }
782     }

org.eclipse.jetty.server.Response (version: 8.1.13.v20130916)

825     /* ------------------------------------------------------------ */
826     /*
827      * @see javax.servlet.ServletResponse#setContentLength(int)
828      */
829     public void setContentLength(int len)
830     {
831         // Protect from setting after committed as default handling
832         // of a servlet HEAD request ALWAYS sets _content length, even
833         // if the getHandling committed the response!
834         if (isCommitted() || _connection.isIncluding())
835             return;
836         _connection._generator.setContentLength(len);
837         if (len>0)
838         {
839             _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len);
840             if (_connection._generator.isAllContentWritten())
841             {
842                 if (_outputState==WRITER)
843                     _writer.close();
844                 else if (_outputState==STREAM)
845                 {
846                     try
847                     {
848                         getOutputStream().close();
849                     }
850                     catch(IOException e)
851                     {
852                         throw new RuntimeException(e);
853                     }
854                 }
855             }
856         }
857     }

sonia.scm.web.cgi.DefaultCGIExecutor

  private void parseHeaders(InputStream is) throws IOException
  {
    String line = null;

    response.setContentLength(-1);

    while ((line = getTextLineFromStream(is)).length() > 0)
    {
      if (logger.isTraceEnabled())
      {
        logger.trace("  ".concat(line));
      }

illegal argument check is added in Response class in version 9.0.6.v20130930.
DefaultCGIExecutor class sets contentLength -1.

Would you be able to fix it ?

Comments (7)

  1. Log in to comment