What Do I Do for an Automatically Disconnected VS Code Connection If No Operation Is Performed for a Long Time?
Symptom
After an SSH connection is set up through VS Code, no operation is performed for a long time and the window retains open. When the connection is used again, it is found that the connection is disconnected and no error message is displayed.
According to VS Code Remote-SSH logs, the connection was disconnected about two hours after the setup.
Possible Cause
After SSH interaction stops for a period of time, the firewall disconnects idle connections (http://bluebiu.com/blog/linux-ssh-session-alive.html). The default SSH configuration does not lead to a proactive disconnection upon timeout. Since the instance runs stably on the backend, set up the connection again to resolve this issue.
Solution
To retain connections if no operation is performed for a long time, configure periodic message sending through SSH. In this way, the connection will not become idle on the firewall.
- Configure the client as needed. If the client is not configured, no heartbeat packet will be sent to the server by default.
Figure 1 Opening the VS Code SSH configuration file
Figure 2 Adding configurations
The configuration is as follows:
Host ModelArts-xx ... ServerAliveInterval 3600 # Add this configuration in the unit of second, indicating that the client will actively send a heartbeat packet to the server every hour. ServerAliveCountMax 3 # Add this configuration, indicating that if the server does not respond after the heartbeat packet is sent for three times, the connection will be disconnected.
For example, if the firewall is configured to disconnect a connection if the connection is idle for two hours, set ServerAliveInterval to a value less than two hours (for example, one hour) on the client to prevent the firewall from disconnecting the connection.
- Configure the server in /home/ma-user/.ssh/etc/sshd_config. (Notebook has been configured, and 24 hours is longer than the time configured on the firewall for disconnecting connections. This configuration does not need to be manually modified. It is only used to help understand the SSH configuration.)
The preceding configuration shows that the server actively sends a heartbeat packet to the client every 24 hours, and the connection will be disconnected if the client does not respond after the heartbeat packet is sent for three times.
For details, see https://unix.stackexchange.com/questions/3026/what-do-options-serveraliveinterval-and-clientaliveinterval-in-sshd-config-d.
- If a connection must be consistently retained, it is a good practice to write logs in a separate log file and run the script on the backend. For example:
nohup train.sh > output.log 2>&1 & tail -f output.log
Failures to Access the Development Environment Through VS Code FAQs
- What Do I Do If the VS Code Window Is Not Displayed?
- What Do I Do If a Remote Connection Failed After VS Code Is Opened?
- Basic Problems Causing the Failures to Access the Development Environment Through VS Code
- What Do I Do If Error Message "Could not establish connection to xxx" Is Displayed During a Remote Connection?
- What Do I Do If the Connection to a Remote Development Environment Remains in "Setting up SSH Host xxx: Downloading VS Code Server locally" State for More Than 10 Minutes?
- What Do I Do If the Connection to a Remote Development Environment Remains in the State of "Setting up SSH Host xxx: Downloading VS Code Server locally" for More Than 10 Minutes?
- What Do I Do If the Connection to a Remote Development Environment Remains in the State of "ModelArts Remote Connect: Connecting to instance xxx..." for More Than 10 Minutes?
- What Do I Do If a Remote Connection Is in the Retry State?
- What Do I Do If Error Message "The VS Code Server failed to start" Is Displayed?
- What Do I Do If Error Message "Permissions for 'x:/xxx.pem' are too open" Is Displayed?
- What Do I Do If Error Message "Bad owner or permissions on C:\Users\Administrator/.ssh/config" or "Connection permission denied (publickey)" Is Displayed?
- What Do I Do If Error Message "ssh: connect to host xxx.pem port xxxxx: Connection refused" Is Displayed?
- What Do I Do If Error Message "ssh: connect to host ModelArts-xxx port xxx: Connection timed out" Is Displayed?
- What Do I Do If Error Message "Load key "C:/Users/xx/test1/xxx.pem": invalid format" Is Displayed?
- What Do I Do If Error Message "An SSH installation couldn't be found" or "Could not establish connection to instance xxx: 'ssh' ..." Is Displayed?
- What Do I Do If Error Message "no such identity: C:/Users/xx /test.pem: No such file or directory" Is Displayed?
- What Do I Do If Error Message "Host key verification failed" or "Port forwarding is disabled" Is Displayed?
- What Do I Do If Error Message "Failed to install the VS Code Server" or "tar: Error is not recoverable: exiting now" Is Displayed?
- What Do I Do If Error Message "XHR failed" Is Displayed When a Remote Notebook Instance Is Accessed Through VS Code?
- What Do I Do for an Automatically Disconnected VS Code Connection If No Operation Is Performed for a Long Time?
- What Do I Do If It Takes a Long Time to Set Up a Remote Connection After VS Code Is Automatically Upgraded?
- What Do I Do If Error Message "Connection reset" Is Displayed During an SSH Connection?
- What Can I Do If a Notebook Instance Is Frequently Disconnected or Stuck After I Use MobaXterm to Connect to the Notebook Instance in SSH Mode?
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbotmore