Web UI Framework

I Get an Error When I Click on Two Links Quickly

Updated: October 16, 2020

This has been fixed for form submission in Nuxeo Platform 5.8 (see NXP-12487).

Sometimes if you click on a link and then, after a very short time, click on another link without waiting the response from the server, you can get a JSF error. This can happen very frequently when using Ajax requests as users does not always see that the server did not answer yet, so it can be easier from them to trigger an additional request.

There is no ideal solution to this problem, so it is important to understand why it is happening before picking a solution.

Seam does not handle concurrent requests in the same conversation simultaneously: when a request arrives, if a preceding request is already being processed, it'll wait for the other request to finish before processing the new one. It does not wait indefinitely: it waits for a given, configurable, amount of time. When this timeout is reached, as the first request is still being processed, the corresponding conversation is locked. So the new request is processed in a "temporary" conversation. This temporary conversation does not hold the contextual information that the request may need, and this would lead to an error.

By default, this timeout (concurrentRequestTimeout) is configured to 1 s, so if your server is quite slow you can set up a higher timeout to avoid this issue. Note that it is important not to setup a value too high: concurrent requests may keep piling up on the server, and may slow it down even more.

To configure a concurrent request timeout, in the OSGI-INF/deployment-fragment.xml of your own project add the definition:

<extension target="components#SEAM_CORE_MANAGER" mode="replace">
  <!-- 30 min = 1800 s = 1800000 ms -->
  <property name="conversationTimeout">1800000</property>
  <!-- 5 s = 5000 ms (default value is 1 s) -->
  <property name="concurrentRequestTimeout">5000</property>
</extension>

At startup, you'll get in nxserver/nuxeo.war/WEB-INF/components.xml a block like:

<component name="org.jboss.seam.core.manager">
  <property name="conversationTimeout">1800000</property>
  <property name="concurrentRequestTimeout">5000</property>
</component>

If this is not enough, or if this problem is happening on some specific pages, the other options you have are :

  • try to optimize the request that takes time: if some request is very slow, users may be tempted to click elsewhere waiting for the server to answer.
  • use Ajax configurations to handle concurrent requests: ajax makes it possible to put requests in a queue so that similar requests are not sent to the server. It also allows to wait for a given amount of time before sending a request, etc...
  • use JavaScript tricks to make it impossible for the user to click somewhere else (or even to keep on clicking on the costly link) while the server has not answered.

 


Related topics