Skip to content

ERROR dispatch can cause two sessions to be created #229

@tsachev

Description

@tsachev

Updated Description

After further feedback from @tsachev the issue is reproduced:

  • Initially there is no session created on the server and no session cookies in the browser.
  • The controller/servlet creates a new session and sets an attribute. then throw an exception
  • The error is handled and the SessionRepositoryFilter is invoked on the ERROR dispatch

This happens because the wrapped request that is caching the current session is not there anymore. It is a new HttpServletRequest object that is no longer wrapped. Instead, we should save the HttpSessionWrapper currentSession in a HttpServletRequest attribute.

Original Description

If a request creates a new session and then forwards (requestDispatcher.forward()) to another servlet/view which tries to update the session - two session are created.

if SessionRepositoryFilter is registered for DisptcherType.FORWARD - two spring sessions are created.
if SessionRepositoryFilter is not registered for DisptcherType.FORWARD - one spring session is created and one tomcat session.

I can see that two Set-Cooke headers are sent to the browser.

HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Set-Cookie: SESSION=8aa5f36e-820c-43bf-ba68-3797fd70b20f; Path=/storefront/; Secure; HttpOnly
Set-Cookie: SESSION=acc2a3df-ab9a-4080-afa3-c740fee75f5b; Path=/storefront/; Secure; HttpOnly
Content-Type: text/html;charset=UTF-8
Content-Language: en-US
Content-Length: 0
Date: Thu, 25 Jun 2015 14:56:10 GMT
Connection: close

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions