VSCode中AWS Toolkit无法通过共享凭证连接AWS账号,报Socket关闭错误
AWS Toolkit for VSCode 连接SAML凭证时“Socket is closed”问题解析
核心问题答案
被关闭的Socket是VSCode的AWS Toolkit插件与AWS服务(或代理服务器)建立的HTTP客户端连接套接字。日志里的statusCode: 407(代理认证要求)是关键线索——这个Socket在尝试通过代理连接AWS服务时,因代理认证失败被远端提前关闭。
关键分析
同一份SAML凭证在IntelliJ中正常,但VSCode的AWS Toolkit与IntelliJ的代理配置相互独立:
- 407状态码明确说明请求被代理服务器拦截并要求认证,但AWS Toolkit未正确提供代理认证信息,导致代理服务器主动关闭了连接Socket
- 错误栈中的
ClientRequest._flushOutput等调用,是Node.js客户端发起HTTP请求时的套接字写入操作,此时Socket已被远端(代理)关闭,因此抛出错误
排查步骤
- 核对VSCode代理配置:打开
settings.json(快捷键Ctrl+,),检查http.proxy、https.proxy、http.proxyAuthorization是否和IntelliJ使用的代理参数完全一致,尤其是企业代理所需的Base64认证串 - 检查AWS Toolkit专属代理设置:在VSCode的扩展设置中找到AWS Toolkit,确认是否开启
aws.proxy.enable,以及是否继承VSCode的全局代理配置 - 用CLI验证凭证有效性:在终端执行
aws --profile=saml sts get-caller-identity,若能正常返回身份信息,说明凭证无问题,故障出在VSCode/AWS Toolkit的网络配置 - 排查本地安全软件:确认防火墙、杀毒软件未拦截VSCode的出站网络请求
用户提供的原始信息
凭证文件
[saml] aws_access_key_id = xxxxxxx aws_secret_access_key = xxxxxxx
错误日志
xxxxxxxxxxxxxxxxxxx [INFO]: autoconnect: trying "profile:saml" xxxxxxxxxxxxxxxxxxx [ERROR]: Error: Socket is closed at new NodeError (node:internal/errors:371:5) at Socket._writeGeneric (node:net:785:8) at Socket._write (node:net:807:8) at doWrite (node:internal/streams/writable:408:12) at clearBuffer (node:internal/streams/writable:569:7) at Socket.Writable.uncork (node:internal/streams/writable:348:7) at ClientRequest._flushOutput (node:_http_outgoing:969:10) at ClientRequest._flush (node:_http_outgoing:938:22) at onSocketNT (node:_http_client:818:9) at processTicksAndRejections (node:internal/process/task_queues:84:21) { code: 'NetworkingError', region: 'xxxxx', hostname: 'xxxxx', retryable: true, time: xxxxxxxxxxxxxxx, statusCode: 407 }
内容的提问来源于stack exchange,提问作者razor1911
相关产品推荐
相关产品推荐

