vscode ssh-remote 疑似内存走漏标题

[复制链接]
发表于 2026-2-9 13:20:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
vscode ssh-remote疑似内存走漏标题

体系信息与版本号

版本:1.88.1(通用)
日期:2024-04-10T17:42:52.765Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium:120.0.6099.291
Node.js:18.18.2
V8:12.0.267.19-electron.0
利用体系:Darwin x64 23.4.0
标题形貌

vscode 的 ssh-remote 插件毗连之后,会发现内存不绝上涨,然后导致云主机瓦解。ubantu22.04与debian等体系均有这种情况。
疑似出现了内存走漏,颠末细致查抄发现vscode-server这个进程会不绝添加新的进程进去,标题复现步调:

  • 使用 TypeScript 文件打开远程工作区
  • 等候“正在初始化 JS/TS 语言功能”状态栏指示器克制出现。
  • 运行此脚本以获取 ionotify 观察步调进程列表:脚本
  • 请注意下令类似于 ~/.vscode-server/cli/servers/Stable-e170252f762678dec6ca2cc69aba1570769a5d39/server/node 的进程数量
  • 重新加载窗口
  • 重复步调 2 到 4,你会发现步调 4 中记下的数字比前次增长了。
脚本

  1. #!/bin/bash
  2. # Get the procs sorted by the number of inotify watches
  3. # @author Carl-Erik Kopseng
  4. # @latest https://github.com/fatso83/dotfiles/blob/master/utils/scripts/inotify-consumers
  5. # Discussion leading up to answer: https://unix.stackexchange.com/questions/15509/whos-consuming-my-inotify-resources
  6. #
  7. # If you need ultimate speed, use https://github.com/fatso83/dotfiles/commit/inotify-consumers-v1-fastest
  8. # # Speed enhancements by Simon Matter <[email protected]>
  9. #
  10. # A later PR introduced a significant slowdown to gain better output, but it is insignificant on most machines
  11. # See this for details: https://github.com/fatso83/dotfiles/pull/10#issuecomment-1122374716
  12. main(){
  13.     # get terminal width
  14.     declare -i COLS=$(tput cols 2>/dev/null || echo 80)
  15.     declare -i WLEN=10
  16.     printf "\n%${WLEN}s  %${WLEN}s\n" "INOTIFY" "INSTANCES"
  17.     printf "%${WLEN}s  %${WLEN}s\n" "WATCHES" "PER   "
  18.     printf "%${WLEN}s  %${WLEN}s  %s\n" " COUNT " "PROCESS "    "PID USER         COMMAND"
  19.     printf -- "------------------------------------------------------------\n"
  20.     generateData
  21. }
  22. usage(){
  23.     cat << EOF
  24. Usage: $0 [--help|--limits]
  25.     -l, --limits    Will print the current related limits and how to change them
  26.     -h, --help      Show this help
  27. EOF
  28. }
  29. limits(){
  30.     printf "\nCurrent limits\n-------------\n"
  31.     sysctl fs.inotify.max_user_instances fs.inotify.max_user_watches
  32.     cat <<- EOF
  33. Changing settings permanently
  34. -----------------------------
  35. echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
  36. sudo sysctl -p # re-read config
  37. EOF
  38. }
  39. if [ "$1" = "--limits" -o "$1" = "-l" ]; then
  40.     limits
  41.     exit 0
  42. fi
  43. if [ "$1" = "--help" -o "$1" = "-h" ]; then
  44.     usage
  45.     exit 0
  46. fi
  47. if [ -n "$1" ]; then
  48.     printf "\nUnknown parameter '$1'\n" >&2
  49.     usage
  50.     exit 1
  51. fi
  52. generateData(){
  53.     local -i PROC
  54.     local -i PID
  55.     local -i CNT
  56.     local -i INSTANCES
  57.     local -i TOT
  58.     local -i TOTINSTANCES
  59.     # read process list into cache
  60.     local PSLIST="$(ps ax -o pid,user=WIDE-COLUMN,command --columns $(( COLS - WLEN )))"
  61.     local INOTIFY="$(find /proc/[0-9]*/fdinfo -type f 2>/dev/null | xargs grep ^inotify 2>/dev/null)"
  62.     local INOTIFYCNT="$(echo "$INOTIFY" | cut -d "/" -s --output-delimiter=" "  -f 3 |uniq -c | sed -e 's/:.*//')"
  63.     # unique instances per process is denoted by number of inotify FDs
  64.     local INOTIFYINSTANCES="$(echo "$INOTIFY" | cut -d "/" -s --output-delimiter=" "   -f 3,5 | sed -e 's/:.*//'| uniq |awk '{print $1}' |uniq -c)"
  65.     local INOTIFYUSERINSTANCES="$(echo "$INOTIFY" | cut -d "/" -s --output-delimiter=" "   -f 3,5 | sed -e 's/:.*//' | uniq |
  66.                  while read PID FD; do echo $PID $FD $(grep -e "^\ *${PID}\ " <<< "$PSLIST"|awk '{print $2}'); done | cut -d" "  -f 3 | sort | uniq -c |sort -nr)"
  67.     set -e
  68.     cat <<< "$INOTIFYCNT" |
  69.         {
  70.             while read -rs CNT PROC; do   # count watches of processes found
  71.                 echo "${PROC},${CNT},$(echo "$INOTIFYINSTANCES" | grep " ${PROC}$" |awk '{print $1}')"
  72.             done
  73.         } |
  74.         grep -v ",0," |                  # remove entires without watches
  75.         sort -n -t "," -k 2,3 -r |         # sort to begin with highest numbers
  76.         {                                # group commands so that $TOT is visible in the printf
  77.             IFS=","
  78.             while read -rs PID CNT INSTANCES; do   # show watches and corresponding process info
  79.                 printf "%$(( WLEN - 2 ))d  %$(( WLEN - 2 ))d     %s\n" "$CNT" "$INSTANCES" "$(grep -e "^\ *${PID}\ " <<< "$PSLIST")"
  80.                 TOT=$(( TOT + CNT ))
  81.                 TOTINSTANCES=$(( TOTINSTANCES + INSTANCES))
  82.             done
  83.             # These stats should be per-user as well, since inotify limits are per-user..
  84.             printf "\n%$(( WLEN - 2 ))d  %s\n" "$TOT" "WATCHES TOTAL COUNT"
  85. # the total across different users is somewhat meaningless, not printing for now.
  86. #            printf "\n%$(( WLEN - 2 ))d  %s\n" "$TOTINSTANCES" "TOTAL INSTANCES COUNT"
  87.         }
  88.     echo ""
  89.     echo "INotify instances per user (e.g. limits specified by fs.inotify.max_user_instances): "
  90.     echo ""
  91.     (
  92.       echo "INSTANCES    USER"
  93.       echo "-----------  ------------------"
  94.       echo "$INOTIFYUSERINSTANCES"
  95.     ) | column -t
  96.     echo ""
  97. }
  98. main
复制代码
原标题网址
简朴来形貌这个标题,就是每次使用ssh-remote毗连之后,会出现一个标题:
   ~/.vscode-server/cli/servers/Stable-…这个进程的数量增长了
  当你关闭毗连后,这个进程不会消散,但是下一次打开毗连后,会产生新的进程,如许的效果就是导致进程数量不绝增长导致占用的内存越来越多,末了导致体系瓦解重启。
修复方式

将 vscode 更新到预发布版本,开发者已经在最新的预发布版本中办理了这个标题。
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表