Iron Golem farm not working when logged out

My Iron Golem farm works normally when I'm on the server, but when I log off it stops working completely. It is in the spawn chunks. I have found that when I log back in, the villagers don't get scared anymore until a new night comes.

How do I fix this problem?

The server has no plugins, and runs Minecraft 1.15.


Spawn chunks might work differently if there was no player there in a long time. The Minecraft wiki says:

Each dimension has its own "idle timeout." Without a player or forceloaded chunks in the overworld, this timeout eventually expires. When the timeout expires, some behaviors such as entity processing stop for spawn chunks and the rest of the dimension. The timeout can be reset by frequently sending entities through a portal.

Source

If you can use operator commands on the server, you can use the /forceload command to keep the chunks loaded, when no players are near or are online. (More details here)

If you have no operator rights, or you just don't want to use commands, you could try and build a machine that loads the chunks (e.g. the machine in this video), but this might not work.

And here's some additional info on chunk loading, if something's still wrong.