https://bz.apache.org/bugzilla/show_bug.cgi?id=66513
Bug ID: 66513 Summary: Primary Key Violation using PersistentManager + PersistentValves + Product: Tomcat 9 Version: 9.0.72 Hardware: PC Status: NEW Severity: normal Priority: P2 Component: Catalina Assignee: dev@tomcat.apache.org Reporter: vincent.liaut...@free.fr Target Milestone: ----- Hi all, when using PersistentManager + org.apache.catalina.valves.PersistentValve to store session data in a Database table (in order to run Tomcat on containers without sticky sessions) we get sometimes a "primary key constraint violation" due to different thread that are badly synchronized. When looking at source code, it appears that the usage of PersistentValve assumes that we get only one request per session at any on time (and you propose a filter parameter on the persistentValve component to avoid having several requests at the same time). However, in the case this filter is not complete (and so we get several requests with the same sessionId at a time), the source code in org.apache.catalina.valves.PersistentValve as well in org.apache.catalina.session.DataSourceStore use a synchronized block to avoid this problem but this synchronized block is useless because it uses a session object that is different for each request. You could solve this issue by using a static HashMap with keys and values storing sessionId string, and using this sessionId string value as an object to synchronize the blocks used to store the session in the DB table. The process could be : -If sessionId String not already store as a HashMap Key -Store sessionId String as key and values Synchronized(theHashMap(sessionId) { .... .... remove it from the hashMap } That way you would really synchronize threads that use a same sessionId (and no more) and would avoid those "primary key violation" errors. Regards -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org