All Products
Search
Document Center

:Session persistence is invalid when you use SLB

Last Updated:May 20, 2022

Question

When the SLB instance is used, session persistence does not work.

Cause

The possible causes are as follows:

  • Session persistence is not enabled in the listener configuration of the SLB instance.
  • The session persistence time is set too low.
  • When HTTP/HTTPS listeners return 4XX HTTP status code to the backend server, the Cookie required for session persistence cannot be inserted into the message, resulting in session persistence failure.
  • By using HTTP/HTTPS listening, when the backend server returns the 302 redirect HTTP status code, the SERVERID string in the session persistence will be changed, causing the session persistence to fail.

Answer

Perform the following steps for troubleshooting and resolution:

  1. Log on to the Alibaba Cloud Console and verify that the listener status of the session persistence is enabled on the listeners tab. If the status is disabled, see add TCP listener to enable session persistence.
  2. Check whether the timeout period of session persistence has been adjusted. If the timeout value is too small, session persistence may fail. Try using the default timeout period or increasing the timeout period as appropriate, and observe the session persistence state. For more information about how to monitor session persistence, see use the curl Command to test the effectiveness of session persistence.
  3. Capture request and response responses in your browser, or use packet capture software to check whether the following packets exist: If the following packets exist, we recommend that you use TCP listeners instead. This is because session persistence for TCP listeners is based on the IP address of the source client. You can also insert a Cookie into the backend Web application and judge the Cookie to ensure that session persistence is valid.
    • 302 redirect: when SLB inserts a Cookie, if the backend ECS instance returns a 302 redirect message, the SERVERID string in the session persistence will be changed, resulting in the session persistence failure.
    • 4XX response code message: SLB cannot insert the Cookie required for session persistence into the 4XX response code message.

Related topics

Scope

  • SLB