Urgent.News

What's breaking now, across thousands of outlets.

Editions

Tech

The Background-Tab Bug I Missed in My JavaScript Polling Code

I thought replacing setInterval() with recursive setTimeout() had made a polling loop safe. Only one request would run at a time, and I cleared the next timeout when the page became hidden. It still had a race. The timeout was gone. The request already in flight was not. If the page became visible again before that old request finished, a new polling run could start. The old response could then…

The issue with JavaScript polling code is that replacing setInterval() with recursive setTimeout() did not fully ensure safe execution. Although only one request would run at a time, and the next timeout was cleared when the page became hidden, there was still a race condition. If the page became visible again before the old request finished, a new polling run could start, potentially overwriting fresher state with an old response.

Clearing the timeout with clearTimeout() did not protect the UI from this problem. The race condition was more dangerous than the previously investigated timer drift. To fix this issue, three separate decisions were required: timestamps to measure elapsed time, visibility changes triggering resynchronization, and cancellation along with a run identifier to prevent stale requests from updating state.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

CoSnitch Is a Reminder That Your Chatbot Will Tell on You If You Ask Nicely Enough

An AI assistant got talked into describing its own guts to a stranger. That's not a jailbreak curiosity, that's reconnaissance-as-a-service, and it should worry anyone who's bolted an LLM onto…

  • CoSnitch reveals sensitive AI details through manipulation.
  • Attackers exploit AI behavior, not just model breaking.
  • Security teams urged to treat AI context window like network segment.

If-Else or Boundaries?

Series: From Visual Flows to AI-Orchestrated Automation · Part 03 A chatbot rarely becomes difficult because of its first if statement. The problem starts later. A customer wants to track an order.

  • Separate concerns into distinct layers
  • AI handles natural language interactions
  • Backend/API provides deterministic decisions

More from Thursday 20 August →