IllegalStateException: Response is committed

Steps to reproduce

IRC Discussion:

```
18:55:49 lkiesow | Does anyone else get a lot of │
18:55:50 lkiesow | (HttpChannel:396) - /admin-ng/event/events.json?filter=status:EVENTS.EVENTS.STATUS.RECORDING&limit=1 │
18:55:51 lkiesow | java.lang.IllegalStateException: Response is committed │
19:07:00 AndChat|190896 | I do │
19:07:04 AndChat|190896 | All the time │
19:07:14 * | AndChat|190896 is greg_logan │
19:07:53 AndChat|190896 | HttpChannel throws that exception for most admin ui requests in my experience. │
19:08:12 AndChat|190896 | No one else was complaining so I assumed it was just on my end and hadn't tracked it down yet │
19:14:27 lkiesow | I did notice it only in the last couple of days │
19:15:15 lkiesow | From when it occurs, I am wondering if it's caused by a dropped tcp connection (Opencast tries to send data but browser is already somewhere else) │
19:15:40 lkiesow | because it's mainly the counter requests if I do a page reload │
19:16:14 lkiesow | I guess we see these errors now since Rubencino made change to the CleanSessionFilter │
19:16:25 lkiesow | which before ate all errors │
19:17:10 lkiesow | But all that is just a guess and I do not have time to investigate
19:17:18 AndChat|190896 | It's been there for a while for me, but that sounds like a reasonable guess. │
19:17:26 * | Rubencino likes to be mentioned for a good cause
19:17:43 AndChat|190896 | I haven't had time either. Can you file an Rb for this Lars? │
19:17:59 AndChat|190896 | This should be fixed prior to 3.0 if others are seeing it
```

Error:

```
2017-05-02 18:59:49,858 | WARN | (HttpChannel:396) - /admin-ng/event/events.json?filter=status:EVENTS.EVENTS.STATUS.PROCESSING&limit=1
java.lang.IllegalStateException: Response is committed
at org.eclipse.jetty.server.Request.getSession(Request.java:1374)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.Request.getSession(Request.java:1352)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.opencastproject.kernel.rest.CleanSessionsFilter.doFilter(CleanSessionsFilter.java:97)[103:matterhorn-kernel:4.0.0.SNAPSHOT]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)[292:org.eclipse.jetty.servlet:9.2.19.v20160908]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)[292:org.eclipse.jetty.servlet:9.2.19.v20160908]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)[314:org.ops4j.pax.web.pax-web-jetty:4.3.0]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[290:org.eclipse.jetty.security:9.2.19.v20160908]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:287)[314:org.ops4j.pax.web.pax-web-jetty:4.3.0]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[292:org.eclipse.jetty.servlet:9.2.19.v20160908]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[314:org.ops4j.pax.web.pax-web-jetty:4.3.0]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.Server.handle(Server.java:499)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[291:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)[283:org.eclipse.jetty.io:9.2.19.v20160908]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[294:org.eclipse.jetty.util:9.2.19.v20160908]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[294:org.eclipse.jetty.util:9.2.19.v20160908]
at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]
2017-05-02 18:59:49,858 | WARN | (HttpChannel:482) - Could not send response error 500: java.lang.IllegalStateException: Response is committed
```

Activity

Show:
Former user
May 2, 2017, 6:28 PM

Maybe change the CleanSessionFilter to request.getSession(false)

"If create is false and the request has no valid HttpSession, this method returns null.
To make sure the session is properly maintained, you must call this method before the response is committed. If the container is using cookies to maintain session integrity and is asked to create a new session when the response is committed, an IllegalStateException is thrown."
http://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletRequest.html#getSession-boolean-

Current line#95-98
else if (request.getHeader("Authorization") != null) {
logger.trace("Invalidating digest request.");
request.getSession().invalidate(); <--- creates a new session if one doesn't exist, throws IllegalState
}
===========================
else if (request.getHeader("Authorization") != null) {
logger.trace("Invalidating digest request.");
HttpSession session = request.getSession(false); // don't create a new session on committed response
if (session != null) {
session.invalidate(); // only invalidate an existing session
}
}

==========================

Lars Kiesow
May 2, 2017, 6:44 PM

Sounds reasonable. If you create a pull request, I promise to review it immediately

Former user
May 2, 2017, 6:54 PM

ok

Fixed and reviewed

Assignee

Unassigned

Reporter

Lars Kiesow

Severity

Usability Issue

Tags (folksonomy)

None

Fix versions

Affects versions

Priority

Blocker