2

I have a basic MERN app in production with a login system that always runs into either an ERR_CONNECTION_RESET or an ERR_CONNECTION_REFUSED AxiosError when first attempting to login after what it seems to be a "long time", usually a day. If I press the login button again right after then it logs in anyway without an issue, and from then keeps working throughout the day. It obviously doesn't happen on my machine, as per usual.

The Axios call on the frontend:

const getData = useCallback(async (path, setData) => {

  Axios.get(`${apiUrl}/api${path}`, { withCredentials: true })
    .then(res => setData(res.data))
    .catch(err => console.log(err))
},
  []
)

While the handling of the call on the backend:

async function handleLogin(req, res) {

  const loginData = req.body;

  const username = loginData.username;
  const password = loginData.password;

  const userData = await getData(undefined, username, password);
  const cookies = getCookies(userData);

  const sessionEnd = new Date(Date.now() + ( 1000 * 60 * 60 * 24 ));
  const cookieOptions = {expires: sessionEnd, httpOnly: false};

  res.cookie("cookies", cookies, cookieOptions).status(200).send(userData);
}

So what could be the cause of this strange bug?

5
  • 2
    If anything, maybe the host puts your application to sleep. The first call might wake it up but not the call fails in the mean time. Or might be it's something in the network stack. This could be client or server side. Maybe more likely client-side - for example, the local DNS drops the cache overnight and somehow has trouble routing the first request but not further requests. Or anything else that might mean first attempt to communicate with the app fails. Whatever the case, it's unlikely to be the code. Commented Oct 31 at 11:32
  • Oh, I see. So I should just let IT know about the issue, see if they can handle it? Commented Oct 31 at 11:38
  • 1
    “Just”? No. But we don’t know anything about the env the app runs in, and it’s obvs not the code, so not much else we can do to help anyway. Commented Oct 31 at 11:42
  • You can try. If the issue is on your side of things (where IT are involved, at least) then maybe they can deal with it. At the very least, they can try to set up some periodic ping to the application. Like once every 30-60 minutes. That might keep the entire tech stack up (network infrastructure, hosting, containers, etc). But if the issue is client-side, not much IT would be able to do. Commented Oct 31 at 11:47
  • Please check your database connection Commented Oct 31 at 16:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.