3 months ago
Hi, I'm using the Postiz (Temporal) template on Railway.
After the initial deploy, I hit the known race condition mentioned in the template docs: "If you run into issues registering or logging in after the first deploy, redeploy the Postiz service. This happens when Postiz starts before Temporal is ready — a one-time race condition that a simple redeploy resolves."
I redeploy the Postiz service, it works — I can log in, connect social accounts, everything is fine.
The problem: whenever I redeploy the Postiz service again even with zero config changes, the NestJS backend stops responding on port 3000 . Every API call fails with connection refused. This happens every single redeploy, not just the first one.
Logs :
2026/03/05 09:49:45 [error] 5#5: *109 connect() failed (111: Connection refused)
while connecting to upstream, client: 100.64.0.11, server: _,
request: "GET /api/user/self HTTP/1.1",
upstream: "http://[::1]:3000/user/self",
host: "postiz-production-3fc5.up.railway.app"
2026/03/05 09:50:16 [error] 5#5: *112 connect() failed (111: Connection refused)
while connecting to upstream, client: 100.64.0.4,
request: "GET /api/user/self HTTP/1.1",
upstream: "http://127.0.0.1:3000/user/self"
My hypothesis: The race condition with Temporal is not a one-time issue — it happens on every redeploy of the Postiz service in isolation. When Postiz restarts, it tries to connect to Temporal immediately on startup, Temporal isn't ready in time, and the NestJS process crashes silently. nginx keeps running but the backend is dead. But what is confusing is that the Temporal services are already running...
Question: Is there a known fix for this ? how can i solve this issue and be able to redeploy my postiz service whenever i want please ?
Thanks
4 Replies
3 months ago
Hi specialone-coder,
For testing, I deployed a new project using the template.
The error message only appears the first time.
After redeploying the Postiz service while all other services are up and running,
there are no errors. I was able to register an account and got redirected to the calendar page. (Check the screenshots attached.)
Attachments
Status changed to Awaiting User Response Railway • 3 months ago
davepoon
Hi specialone-coder, For testing, I deployed a new project using the template. The error message only appears the first time. After redeploying the Postiz service while all other services are up and running, there are no errors. I was able to register an account and got redirected to the calendar page. (Check the screenshots attached.)
3 months ago
Hi, thank you so much for testing this!
Glad it works on a fresh deploy. To clarify the exact scenario where I hit the issue:
After the initial setup and first successful redeploy (where everything works), if I redeploy the Postiz service again, whether to add new environment variables (like TikTok credentials) or even with absolutely no changes at all, the backend dies again with the same connection refused error on port 3000.
So the pattern is:
1. Fresh deploy → race condition → redeploy Postiz → works
2. Redeploy Postiz again for any reason → breaks again
It seems like the race condition with Temporal is not a one-time thing but happens on every subsequent redeploy of the Postiz service. Have you been able to reproduce this by redeploying the Postiz service a second or third time after it’s fully stable?
Status changed to Awaiting Template Creator Response Railway • 3 months ago
3 months ago
Solved it by adding this script in the postiz service Settings > Deploy > Custom Start Command
sh -lc "(node -e 'const net=require(\"net\");const sleep=ms=>new Promise(r=>setTimeout(r,ms));const parse=(v,d)=>{if(!v)return null;try{if(v.includes(\"://\")){const u=new URL(v);return{host:u.hostname,port:Number(u.port||d),name:v}}}catch{}const m=v.match(/^\\[?(.*?)\\]?:([0-9]+)$/);return m?{host:m[1],port:Number(m[2]),name:v}:null};const probe=t=>new Promise((res,rej)=>{const s=net.connect({host:t.host,port:t.port});s.setTimeout(2000);s.on(\"connect\",()=>{s.destroy();res()});s.on(\"timeout\",()=>{s.destroy();rej(new Error(\"timeout\"))});s.on(\"error\",e=>{s.destroy();rej(e)})});async function wait(t,timeout=300000){const end=Date.now()+timeout;let n=0;while(Date.now()<end){n++;try{await probe(t);console.log(\"ready:\",t.name);return}catch(e){const b=Math.min(1000*Math.pow(1.5,n),10000);console.log(\"waiting:\",t.name,e.message,\"retry in\",Math.round(b),\"ms\");await sleep(b)}}console.error(\"timeout waiting for\",t.name);process.exit(1)};(async()=>{for(const t of [parse(process.env.TEMPORAL_ADDRESS,7233),parse(process.env.DATABASE_URL,5432),parse(process.env.REDIS_URL,6379)].filter(Boolean))await wait(t)})().catch(()=>process.exit(1))') && nginx && (pnpm run pm2-run & PM2PID=$!; node -e 'const net=require(\"net\");const sleep=ms=>new Promise(r=>setTimeout(r,ms));const probe=()=>new Promise((res,rej)=>{const s=net.connect({host:\"127.0.0.1\",port:3000});s.setTimeout(2000);s.on(\"connect\",()=>{s.destroy();res()});s.on(\"timeout\",()=>{s.destroy();rej(new Error(\"timeout\"))});s.on(\"error\",e=>{s.destroy();rej(e)})});(async()=>{const end=Date.now()+180000;let n=0;while(Date.now()<end){n++;try{await probe();console.log(\"backend port ready: 3000\");break}catch(e){const b=Math.min(1000*Math.pow(1.4,n),5000);console.log(\"waiting for backend 3000:\",e.message,\"retry in\",Math.round(b),\"ms\");await sleep(b)}}if(Date.now()>=end){console.error(\"backend never became ready on 3000\");process.exit(1)}let fails=0;for(;;){await sleep(5000);try{await probe();fails=0}catch(e){fails++;console.log(\"backend 3000 healthcheck failed\",fails,e.message);if(fails>=3){console.error(\"backend 3000 unhealthy, exiting container\");process.exit(1)}}}})().catch(()=>process.exit(1))' || { kill $PM2PID 2>/dev/null || true; exit 1; }; wait $PM2PID)"
3 months ago
Great to hear you've fixed the issue. Consider testing your script to see if it solves it better. Thanks.
Status changed to Awaiting User Response Railway • 3 months ago
Status changed to Solved davepoon • 3 months ago