Guides

How to Stop All Running Queries in Retool Programmatically

OTC Team··4 min read

If you've tried to stop all running queries in Retool programmatically, you've probably already discovered the hard truth: there's no built-in runningQueries.stopAll() method. This gap is a real problem for anyone building dynamic Retool apps — especially when you're managing paginated data queues, chained query promises, or any pattern where multiple queries fire in parallel and the user can change context mid-flight.

Why This Problem Bites So Hard in Retool

Here's the scenario that breaks things: you build a queue of objects by triggering a series of paginated queries. As each page returns, it spawns more queries to fetch related objects. The user then switches queue types before all those in-flight requests complete. Now you have a race condition — results from the old queue start arriving and populating the new queue's state. Your UI shows corrupted, mixed data and there's no clean way to flush it.

This is exactly what the Retool community thread on stopping running queries describes. Multiple developers have bumped the thread over the years, and as of now, Retool has acknowledged the request but it remains unimplemented — deprioritized in favor of other platform work.

What Retool Currently Lacks

To be specific, there is no way to:

  • Cancel an in-flight HTTP or database query mid-execution from JavaScript
  • Call something like queryName.cancel() or retool.stopAllQueries()
  • Abort a promise chain once a query sequence has started

Retool's query model doesn't expose an AbortController or equivalent hook. Once a query fires, it runs to completion (or failure) regardless of what happens in your app state afterward.

Practical Workarounds You Can Use Right Now

Until Retool ships a native cancel API, here are the patterns that actually work in production:

1. Use a "Session Token" Guard Pattern

This is the most reliable workaround. The idea: every time the user triggers a new queue context, you generate a new session ID and store it in a tempState variable. Each query callback checks whether the session ID it was spawned under still matches the current one before it writes any results to state.

  • Create a tempState variable called activeQueueSession
  • On queue switch, run: activeQueueSession.setValue(Date.now())
  • At the start of each query's success handler, capture the session: const mySession = activeQueueSession.value
  • Before writing results, check: if (activeQueueSession.value !== mySession) return;

This won't stop the network request from completing, but it will prevent stale results from ever touching your app's state. For most UI use cases, this is equivalent to cancellation.

2. Separate State Variables Per Queue Type

The original thread author mentioned this and dismissed it as less handy — but it's worth reconsidering for simpler apps. If your queue types are finite and known, maintaining a tempState object per queue type means results always land in the right bucket and switching contexts just means swapping which variable your UI reads from.

  • Define queueStateA, queueStateB, etc. as separate tempState variables
  • Each query writes to its own dedicated state, never shared
  • A activeQueueType variable controls which state the UI renders

This approach breaks down when queue types are dynamic or when you have deeply nested sub-promise chains — a limitation explicitly called out in the community thread.

3. Gate Queries Behind a "Should Run" Flag

For chained query sequences, add a tempState boolean called queueActive. Set it to false when the user switches context. At every link in your query chain — in the success handler before triggering the next query — check if (!queueActive.value) return;. This stops the chain from propagating even if individual requests complete.

Why App Loading Performance Is Also at Stake

One community member noted that a stop-all mechanism would cut app loading times significantly. That makes sense: if stale queries are completing and triggering re-renders or additional downstream queries, they're burning browser and server resources on work that will be thrown away. The session token pattern above helps here too — by short-circuiting success handlers early, you avoid the cascading re-renders that stale results cause.

How to Track When Retool Ships This Natively

Retool has the feature request internally logged. When it ships, you'd expect an API something like queryName.cancel() at the individual query level or a global retool.cancelAllQueries() utility. Keep an eye on the original community thread — Retool's team has promised to update it when there's news.

The Bottom Line

There's no native way to stop all running queries in Retool programmatically today. But the session token guard pattern gives you the same practical outcome: stale results are silently discarded before they can corrupt your app's state. Implement it once as a convention in your query success handlers and you'll eliminate the race condition for good — no platform update required.

If you're building complex Retool apps with dynamic data queues, chained queries, or high-concurrency patterns and need a more robust architecture, reach out to our team. We build and maintain production Retool apps for companies that can't afford data integrity bugs.

Ready to build?

We scope, design, and ship your Retool app — fast.

Ready to ship your first tool?