Sling Post Servlet 500 Error with Rapid Requests or Slow Network | Community
Skip to main content
Level 3
October 16, 2015
Solved

Sling Post Servlet 500 Error with Rapid Requests or Slow Network

  • October 16, 2015
  • 3 replies
  • 910 views

We're trying to use the SlingPostServlet to save content to a page when an author interacts with various input. For example, we have a checkbox in the authoring environment that will post it's "checked" status every time it is clicked. This works well, except when the user clicks the checkbox rapidly or if the network is sluggish. This causes two or more requests to go out to the same node and at least one of the responses will return a 500 internal server error with the following message -

org.apache.sling.api.resource.PersistenceException: Unable to commit changes to session.

I'm assuming this is happening because the node is locked by the first request when the second request tries to alter the value. Is there any easy way to get around this from the server side? The only solution i've thought of is to use javascript and build a queueing system for the requests on the client side so we only allow one request at a time, but it makes me nervous to queue up data like that.

Thanks

Best answer by Mshaji

Do you have clustered enviroment? if so, you can look at the following post

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.35.html/forum__jetu-we_are_runningoura.html

What happens is when you are continuously hitting it makes a server call which calls session.save for each hit. Some how if you have network problems or not enough gap between the request, this creates a conflict with previous request. Resulting in this exception.

3 replies

MshajiCommunity AdvisorAccepted solution
Community Advisor
October 16, 2015

Do you have clustered enviroment? if so, you can look at the following post

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.35.html/forum__jetu-we_are_runningoura.html

What happens is when you are continuously hitting it makes a server call which calls session.save for each hit. Some how if you have network problems or not enough gap between the request, this creates a conflict with previous request. Resulting in this exception.

jocampAuthor
Level 3
October 16, 2015

Thanks, we're only running one author server so this isn't applicable to our situation. I'll most likely end up writing the queue system in javascript so only one request goes out at a time.

AmitVishwakarma
Community Advisor
Community Advisor
January 18, 2025

To avoid the 500 error from concurrent requests on the same node:

  1. Use JCR Locks: Lock the node before writing and unlock after saving.
  2. Use Transactions: Commit multiple changes within one transaction.
  3. Throttle Client Requests: Limit rapid clicks with JavaScript to avoid multiple simultaneous requests.
  4. JCR Event Listeners: Use event listeners to monitor and handle changes safely.

These methods will help prevent conflicts and the 500 error.