Skip to content

[Bug] 登录页 getCaptcha 函数存在定时器泄漏问题,导致验证码接口被频繁重复请求 #118

Description

@Jarven89

Bug 描述

登录页面(login.vue、login2.vue、login3.vue)中的 getCaptcha() 函数存在定时器泄漏问题。当用户在登录页面停留时间较长、网络不稳定或后端验证码服务异常时,前端会不断向 /login/getCaptcha 接口发送请求,严重时可能导致服务器压力过大。

复现步骤

  1. 打开登录页面(任意主题样式)
  2. 断网或关闭后端验证码服务
  3. 尝试登录或刷新验证码
  4. 观察网络请求,控制台会不断输出验证码请求

问题根因

文件位置:admin-web/src/views/system/login*/login.vue

问题代码:

async function getCaptcha() {
  try {
    let captchaResult = await loginApi.getCaptcha();
    captchaBase64Image.value = captchaResult.data.captchaBase64Image;
    loginForm.captchaUuid = captchaResult.data.captchaUuid;
    beginRefreshCaptchaInterval(captchaResult.data.expireSeconds);
  } catch (e) {
    console.log(e);
  }
}

function beginRefreshCaptchaInterval(expireSeconds) {
  if (refreshCaptchaInterval === null) {
    refreshCaptchaInterval = setInterval(getCaptcha, (expireSeconds - 5) * 1000);
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions