Scheduled Jobs Running Twice? Causes and Fixes

Your nightly import shows up twice in the log for one window. Before you paste a lock into the crontab, find out which of two different failures you have, because the usual fix only works on one of them.
Scheduled jobs running twice come from two causes. Either one run started before the last one finished, an overrun, or two triggers fired the same job, a duplicate. A lock that refuses to wait fixes the first and does nothing reliable about the second. The fix that covers both is a job that changes nothing when run twice. In the runs we did for this post on 2026-11-30, a job that appends rows reported 32 units of stock after running twice, double the 16 its source held; the same job written as an upsert held 2 rows and the source's total. Every transcript below comes from those runs, trimmed to the lines that matter.
Scheduled jobs running twice: an overrun or a second trigger?
There are two causes and they need different fixes. If one run started before the last one finished, you have an overrun, and a lock that fails instead of waiting will stop it. If two schedulers each hold the same job, no lock helps reliably until you remove one of them. Make the job safe to run twice either way.
Read the raw log first. An overrun shows a start before the previous end, on one host. A duplicate shows two starts for one window, often from two hosts.

Why is my cron job running twice?
A cron job running twice is usually one of four things, and only one of them is cron itself misfiring. Check them in this order.
The job is overrunning its interval. Cronitor's guide to duplicate cron jobs, by Shane Harter and last updated 9 October 2026, read 2026-11-30, says that when you find several copies running, cron itself probably did not fire the job twice; it is usually a job that hangs or runs longer than its interval. Print the start and end times of the last few runs. If any start falls before the previous end, this is your cause.
The line is in the crontab twice. The same guide names a copied and pasted crontab line as the last thing to check. Run crontab -l for every user that might own the job, and look in /etc/cron.d too.
Two schedulers hold the same job. A second server with the same crontab, a framework scheduler that starts inside every web worker, or a beat process plus a crontab calling the same task. Each fires on time, and the second run looks normal.
The clock went backwards. On the night clocks fall back, one hour happens twice. The cron(8) manual for cronie, read 2026-11-30, says that "if time was adjusted backward, running the same job twice is avoided", and Cronitor's guide says the cron implementations in use today do not double run because of a daylight saving change. A scheduler inside your application is a different program, so check its documentation or run it on UTC, which Celery's periodic task documentation gives as its default.
Cause one: the job overran into its own next run
An overrun is fixed with a non-blocking lock: the second run tries to take the lock, fails at once, and exits without doing any work. A lock that waits instead just queues the overlapping runs behind each other, and on a job that keeps overrunning, the queue only grows.
The flock(1) manual at man7.org, read 2026-11-30, defines its -n option as "Fail rather than wait if the lock cannot be immediately acquired." That is the usual answer to how to prevent overlapping cron jobs:
*/5 * * * * flock -n /var/lock/nightly-import.lock /opt/jobs/nightly-import.sh
The flock command is part of util-linux and is not installed on the Mac we tested on. Its manual describes it as managing flock(2) locks, so we wrote a short Python wrapper around the same flock(2) system call and ran that:
#!/usr/bin/env python3
"""run_once.py LOCKFILE COMMAND [ARGS...]
Run COMMAND only if no other copy holds LOCKFILE. Never waits."""
import fcntl, os, sys, time
def log(msg):
print(f"{time.strftime('%H:%M:%S')} pid={os.getpid()} {msg}", flush=True)
lock_path, cmd = sys.argv[1], sys.argv[2:]
fd = os.open(lock_path, os.O_RDWR | os.O_CREAT, 0o644)
try:
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB) # fail, do not wait
except BlockingIOError:
log(f"SKIPPED: {lock_path} is held by another run")
sys.exit(75) # EX_TEMPFAIL, so the skip is visible to whatever called us
log(f"LOCKED {lock_path}, starting {' '.join(cmd)}")
os.set_inheritable(fd, True) # the job itself holds the lock until it exits
os.execvp(cmd[0], cmd)
Then we forced the overlap on purpose. Run A starts a job that takes 6 seconds. Run B fires 2 seconds later, as the next tick would on a job that has outgrown its interval. Run C fires after A is done:
16:42:27 pid=51244 LOCKED nightly-import.lock, starting ./job.sh 6
16:42:29 pid=51249 SKIPPED: nightly-import.lock is held by another run
run B exit code: 75
16:42:33 pid=51253 LOCKED nightly-import.lock, starting ./job.sh 1
-- job log (what actually ran):
16:42:27 pid=51244 job START
16:42:33 pid=51244 job END
16:42:33 pid=51253 job START
16:42:34 pid=51253 job END
The job log is the proof, not the exit code. Run B never wrote a START line, and the job never ran twice at the same time.
Two details are deliberate. The skip exits with 75, so a monitor can tell a refusal from a crash; flock(1) exits 1 on a conflict by default, and its -E option changes that. And the job itself inherits the lock, which matters once something gets killed.
Cause two: two schedulers fire the same job
When two schedulers fire the same job, the fix is to delete one of them, because a lock only helps when the two runs happen to overlap in time. If the job finishes before the second trigger arrives, the lock is free, the second run takes it legitimately, and the work happens twice.
We ran exactly that: the same wrapper and lock file, a job that takes 1 second, and a second trigger 3 seconds after the first, which is what clock skew, a restart or a second scheduler looks like:
16:42:34 pid=51260 LOCKED nightly-import.lock, starting ./job.sh 1
16:42:37 pid=51266 LOCKED nightly-import.lock, starting ./job.sh 1
-- job log:
16:42:34 pid=51260 job START
16:42:35 pid=51260 job END
16:42:37 pid=51266 job START
16:42:38 pid=51266 job END
job STARTs in one window: 2
The lock worked perfectly and the job still ran twice in one window. This is why cron job locking is the wrong tool for this cause: the lock answers "is another copy running right now", and the real question is "has this window already been done". And that was the generous case, with both triggers on one machine. Two servers do not share a lock file, and the flock(1) manual warns that NFS and CIFS have a limited implementation of flock(2), so a lock file on a shared mount is no way round it.
Celery says this in its own documentation. The Celery periodic tasks guide, read 2026-11-30, states: "You have to ensure only a single scheduler is running for a schedule at a time, otherwise you’d end up with duplicate tasks." On the overrun case it is careful to stay conditional: "Like with cron, the tasks may overlap if the first task doesn’t complete before the next. If that’s a concern you should use a locking strategy to ensure only one instance can run at a time". Two causes, two separate sentences, on one page.
Spring has the same shape: Anupam Sinha's Medium post of 7 October 2026 notes, in its readable preview, that a @Scheduled method runs once per application instance. Weighing Django against Spring Boot for a new service? Count the schedulers each design gives you, keep one, and delete the rest.
What happens to the lock if the job crashes?
It depends on the lock, and the three common kinds behave in three different ways when the holder is killed. We killed each holder with kill -9 on 2026-11-30 and watched what the next run could do.
A file lock taken with flock(2) is released by the kernel the moment the holder dies. The empty lock file stays on disk and is harmless: in our run the next start took the lock in the same second. Unless the job had already started a child process. Our job is a shell script that calls sleep, and we killed the script but not its child, which is easy to do by accident:
16:44:06 killed script pid=51397 with SIGKILL
processes still holding nightly-import.lock:
sleep pid=51400
16:44:07 pid=51406 SKIPPED: nightly-import.lock is held by another run
16:44:08 killed orphan child pid=51400
16:44:08 pid=51412 LOCKED nightly-import.lock, starting ./job.sh 1
The orphan inherited the open file, so it held the lock. The flock(1) manual covers the same behaviour from the other side: its -o option exists because "This is useful if command spawns a child process which should not be holding the lock." So when a locked job looks stuck after a crash, run lsof on the lock file first. Cronitor's guide adds: "Removing the lock file with rm does not stop a process that still holds the lock."
A lock file checked with test -e is never released. This is what people usually mean by a stale lock. The script writes its PID, is killed before its cleanup line, and every later run sees the file and skips:
16:44:10 killed holder pid=51418 with SIGKILL
naive.lock contains pid 51418; is that process alive? no
16:44:13 pid=51438 SKIPPED: naive.lock exists
That job now skips every run until a person deletes the file. Replace it with a real lock.
A Postgres advisory lock lasts as long as the database session, and the session can outlive the client. The PostgreSQL documentation on explicit locking, read 2026-11-30, says "Once acquired at session level, an advisory lock is held until explicitly released or the session ends." On PostgreSQL 16.15, with the holder idle between queries, killing the client released the lock in the same second: pg_try_advisory_lock(42) in a second session went from false to true. With the holder in the middle of a 20 second query, the server finished the query for the dead client and kept the lock until then:
17:07:48 psql client pid=58956 (psql)
17:07:49 after kill -9, psql alive? no
17:07:49 second session try_lock: f backend in pg_sleep: 1
17:08:05 second session try_lock: f backend in pg_sleep: 1
17:08:09 second session try_lock: t backend in pg_sleep: 0
PostgreSQL's client_connection_check_interval setting, off by default, exists for this case. Set to 1 second in the holder's session, it ended the orphaned query, and the lock was free 4 seconds after the kill.
A Redis lock with a TTL survives the crash for exactly as long as the TTL. We took the lock with SET lock:nightly-import run-A NX PX 15000 at 16:46:58 and killed the holder. Every attempt by the next run was refused while the key still read run-A, until it expired:
16:47:00 killed holder with SIGKILL
16:47:14 next run SET NX: OK TTL left ms: 14989 value: run-B
The TTL is also the trap: it has to be longer than the job, and nothing makes it so. We set a 3 second TTL on a job that takes 8 seconds. Run B took the lock at 4 seconds while run A was still working, renewed it, and when run A finished it deleted run B's lock with a plain DEL:
16:47:32 run A SET NX PX 3000: OK run A starts an 8s job
16:47:36 run B SET NX PX 3000: OK run B starts while run A is still working
16:47:37 run B renews its own lock to 30s: OK
16:47:40 lock value before run A cleans up: run-B
16:47:40 run A finishes and deletes the lock without checking the owner: DEL -> 1
Redis's own distributed lock page, read 2026-11-30, warns: "Using just DEL is not safe as a client may remove another client's lock." It releases only a lock whose random value the client set itself.
Lock | Holder killed with kill -9 | Job runs longer than the lock | Shared across hosts |
|---|---|---|---|
flock(2) file lock | Released at once, unless a child process still holds the file | Cannot happen, the lock lasts as long as the process | No, one machine |
Postgres advisory lock, session level | Released at once if idle, held until a running 20 second query finished | Cannot happen while the session lives | Yes, every host that reaches the database |
Redis SET NX with a TTL | Held for the rest of the TTL, 14 seconds of 15 in our run | The lock expires and a second run gets in | Yes |
Lock file checked with test -e | Never released, every later run skipped | Not applicable | No |
The 14 seconds is the gap between the kill at 16:47:00 and the next run's success at 16:47:14.
Can you run two cron jobs at the same time?
Yes. Cron starts each due line on schedule and does not check whether the previous copy has finished, so two different jobs, or two copies of the same job, can run at the same moment. Celery's documentation puts it as "Like with cron, the tasks may overlap", which is the same behaviour.
Two different jobs together is usually fine if they do not write the same rows. Two copies of one job is the overrun case above.
How often can cron jobs run? Standard cron's smallest unit is one minute, from the five time fields in crontab(5). For anything more frequent, a long running worker with its own loop is usually a better design than cron.
Make the job safe to run twice
The fix that covers both causes is idempotency: design the job so that a second run over the same window corrects the data rather than adding to it. Then an overrun the lock missed, a second scheduler you have not found yet, and a manual re-run all have the same effect as one run.
We ran the same import twice in two forms. Two products, one snapshot date. The append version inserts rows. The upsert version has a primary key on the source identifier plus the snapshot date, and its second run sees a restated quantity for one product, which is how real source systems behave:
create table stock_upsert (channel_sku text, snapshot_date date, qty int,
primary key (channel_sku, snapshot_date));
insert into stock_upsert values ('SKU-1','2026-11-30',12),('SKU-2','2026-11-30',3)
on conflict (channel_sku, snapshot_date) do update set qty = excluded.qty;
After two runs each, the append table held 4 rows and a total stock of 32. The upsert table held 2 rows and a total of 15, with the restated quantity of 3 in place of the original 4. One job reported double the stock and nothing errored. The other was correct and had picked up the correction.
Choosing the key is most of the work. It has to be something the source system owns and does not change, plus the window the run covers. A sequence number you generate on insert is useless, because the second run generates a new one. Every upsert also needs a guard that refuses to replace newer state with older state, or a late, stale pull can overwrite a fresh one.
Side effects need their own key. An upsert makes the database idempotent. It does not stop the job sending an email twice or calling a payment API twice. Record each send under a key for the window, or pass the provider an idempotency key, the way our returns post puts an idempotency key on the refund call and our agentic RAG post uses an idempotency key derived from the run id and the step. Payments show the cost of getting retries wrong in sharper form, where retrying a hard decline can attract fines.
Inventory is where this goes wrong most visibly, which is why every inventory message needs an idempotency key. In banking, a core's business date need not match the wall clock, so a job posting near midnight defines its window in the core's terms; see a batch window that nobody scoped.
Once the job is idempotent, the lock is no longer what keeps the data correct. It is an optimisation that stops two copies wasting the same compute, and if it fails, the cost is time, not wrong numbers.
A skipped run is an outage too
A lock that refuses the second run has created a missing run, and a missing run is silent by default. The overrun did not go away. The job is still too slow for its interval, and now some windows get no fresh data while every exit code looks fine.
So treat the refusal as an event. Our wrapper exits 75 on a skip for that reason. Count skips, and alert when a job skips twice in a row, because it is then permanently slower than its schedule and the lock is hiding it.
Monitor for the run that did not happen. A failed run produces an error somewhere; a run that never started produces nothing. Cronitor's guide makes the point concretely: with the lock outside its monitoring wrapper, a skipped run sends no ping and shows as a missed execution, and with the monitor outside the lock, the skip shows as a failure with exit 1. Pick one on purpose. Our AI observability post makes the general case that you cannot debug what you did not record: record that each run started, finished, and which window it covered.
If the job overruns regularly, run it less often, make it faster, or split it. A job that walks every tenant in turn grows with the tenant count, like running every migration once per tenant, and splitting it per tenant usually fixes it.
Two schedulers on one Django platform: what we got wrong
We built the Stylebank platform, which runs four apparel businesses on one Django codebase. Around thirty-five scheduled jobs run on django-crontab, and Celery workers on Redis run the ETL. Our own case study, where we record open questions, says it in one line: "Two schedulers is one too many: django-crontab and Celery overlap."
That is a statement about the design, not a report of a job running twice in production. Two scheduling systems in one product are two places a job can be fired from, which is exactly when a lock stops being enough.
What makes it survivable is a decision about ingestion. We chose scheduled pulls with idempotent upserts over webhooks and streaming from each upstream system, because several sources publish on their own batch schedule with no usable event stream, and a re-runnable pull recovers more cheaply than a missed event. Pulls upsert on the channel's identifier and carry a snapshot date, so when a marketplace restates a sale, sometimes weeks later, the restatement corrects the row instead of adding one.
The cost we accepted is written down too: "Data is only as fresh as its cron window". Whatever a planner reads is as old as the last pull.
The lesson for any Django product with this much scheduled work: pick one scheduler before the second job is written. Our introduction to what Django is used for covers the framework, the comparison of Celery for background tasks in a Django versus FastAPI choice shows where a task queue enters either design, and our Django development team works on platforms like this one.
How do I stop a cron job from running?
To stop a cron job from running on future schedules, remove or comment out its line with crontab -e for the user who owns it, or delete its file from /etc/cron.d. To stop a copy that is running right now, stop the process itself, because editing the crontab does not touch a job that has already started.
Kill the whole process group, not only the PID you see first, or a child can keep holding the lock, as our orphaned sleep did. And do not delete a flock lock file to clear a stuck run; stop the process that holds it.
For a job fired by Celery beat or a framework scheduler, remove the entry from its schedule and restart every process that loaded it. If the job still fires after that, you have found a second scheduler. Count the places a job can be fired from, keep one, and make the job safe to run twice so that the next one you miss costs nothing.
Frequently asked questions
Scheduled jobs run twice for one of two reasons. Either a run took longer than its interval and the next run started before it finished, which is an overrun, or two separate triggers fired the same job, such as two servers with the same crontab, a scheduler started inside every app instance, or a duplicated crontab line. Read the raw log: a start before the previous end on one host is an overrun, and two starts for one window, often from two hosts, is a second trigger.
A lock stops an overrun, where the second run starts while the first is still going. It does not reliably stop a second scheduler. In our test on 2026-11-30, two triggers 3 seconds apart on a job that took 1 second both took the same lock file in turn, and the job ran twice in one window with no error. Remove the extra scheduler, and make the job idempotent so a second run changes nothing.
Wrap the command in a lock that fails instead of waiting, such as `flock -n` with a lock file, so a second copy exits at once if the first still holds the lock. The flock(1) manual defines `-n` as failing rather than waiting if the lock cannot be immediately acquired. Then alert on skipped runs, because a job that keeps overlapping is too slow for its schedule and the lock only hides it.
The kernel releases a flock lock when the last process holding the open file exits, so a killed single process frees it at once and the lock file left on disk is harmless. In our test the next run took the lock in the same second. The exception is a job that started child processes: a child inherits the open file and keeps holding the lock after its parent is killed, so check with `lsof` and stop the whole process group.
It works if the TTL is always longer than the job, and nothing enforces that. In our test, a 3 second TTL on an 8 second job let a second run take the lock while the first was still working, and the first run then deleted the second run's lock with a plain DEL. Redis's own documentation says using just DEL is not safe and recommends releasing only a lock whose value you set. If the holder crashes, the lock stays until the TTL expires.
Write results with an upsert keyed on an identifier the source system owns plus the window the run covers, so a second run updates the same rows instead of inserting new ones. In our test, an append job run twice held 4 rows and double the stock, while the upsert version held 2 rows with the correct, restated quantity. For side effects such as emails or payments, record each send under a key for the window, or pass the provider an idempotency key.
Celery beat runs a task twice if more than one beat scheduler is running for the same schedule. Celery's periodic tasks documentation says you have to ensure only a single scheduler is running for a schedule at a time, otherwise you end up with duplicate tasks. Separately, it says that like with cron, tasks may overlap if the first does not complete before the next, and that if that is a concern you should use a locking strategy.

Vikas Choudhary
Vikas has around fifteen years of experience building software and now builds generative AI systems at Zyneto. His work covers retrieval augmented generation, agentic AI, knowledge graphs, AI memory, and the evaluation and guardrails that decide whether any of it is safe to put in front of customers. He has shipped enterprise copilots, document AI, chatbots and predictive analytics for e-commerce, fintech and marketing teams, and works day to day in Python, JavaScript and SQL. He follows multimodal models, business process automation and enterprise AI security closely, and mentors engineers moving into AI. He writes about architecture, inference cost and the failure modes that only show up at production scale.
Zyneto builds custom software, AI and automation
Tell us what you are building and we will reply with a clear next step.









