If a sidecar proxy is injected into a pod, time-consuming requests may get lost or fail after the pod stops. This topic provides the description and causes of this issue, and solutions to this issue.
Problem description
- Some time-consuming requests to this pod are lost.
- Requests initiated by using this pod to other Services fail.
Causes
After a sidecar proxy is injected into a pod, the traffic of the pod is controlled by the sidecar proxy. After the pod stops, the corresponding Service no longer routes the traffic to the pod.
By default, Istio forcibly stops the sidecar proxy 5 seconds after Istio receives the signal that the pod is stopped. After the sidecar proxy is stopped, no inbound traffic is received, but the established inbound connections can still be processed. Outbound connections are not affected and can be initiated as expected. If the requests to the pod of the Service that is stopped are time-consuming, the existing inbound and outbound connections are terminated regardless of whether the connections are processed.
Solutions
Solution 1: Modify the termination drain duration for sidecar proxies
You can extend the termination drain duration for sidecar proxies so that inbound and outbound connections can be processed within this period.
- Log on to the ASM console.
- In the left-side navigation pane, choose .
- On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column.
- On the details page of the ASM instance, choose in the left-side navigation pane.
- On the Sidecar Proxy Setting page, click Namespace.
- Select a namespace from the Namespace drop-down list. Click Lifecycle Management, enter a proper value in the Sidecar proxy termination duration time field, and then click Update Settings.
Solution 2: Configure the lifecycle of sidecar proxies
If you cannot estimate the maximum amount of time to wait for a request, we recommend that you set the preStop parameter to configure the lifecycle of sidecar proxies. The preStop parameter is used to check whether a request exists. If no requests exist, the sidecar proxy stops after the default amount of time, which is 5 seconds, elapses.