For Workers & Pages, what is the name of the domain?
api.pennylabs.net
What is the error number?
400
What is the error message?
400 Bad Request
What is the issue or error you’re encountering
When running workers locally via wrangler dev
http connections get disconnected after around 20 minutes and only a minute or two for web sockets making local development a real pain
What steps have you taken to resolve the issue?
This is really annoying and makes developing locally a pain, and if I recall correctly it wasn’t this bad at the beginning when I started using workers around a year ago. But as of the last few months the time has gotten shorter and shorter to disconnect or the connections have become more fragile. Whatever the reason I was hoping to get some validation as to whether this is some known issue that others also encounter or if this is some bad code or configuration on my end that’s causing it. I don’t think it’s the latter though.
Previously the web socket connections would stay connected for around 30 minutes before disconnection automatically, I use it for a chat application and I could for example send a chat message at 1pm and another at 1:25pm without doing anything with the app in the mean time and it would work. It was only after around 30 minutes the connection would fail and I would need to reconnect. Now after just a minute or two at most of inactivity the connection disconnects. And no it’s not due to the client going to sleep which forces it to disconnect or anything like that.
For http connections whether there is activity or inactivity doesn’t seem to matter, the connection fails in either case if it’s been more than around 20 min since I started wrangler so to get it to work again I need to constantly kill the process and re-enter the wrangler dev
command in my terminal.
Both issues (http and web sockets) occur whether I run wrangler on localhost or local network ip address. I am also running https and wss secure protocols locally and not http or ws. I also have a ping/png mechanism set up on the web socket handler to keep the connection alive by sending a ping message which the client responds to every 30 seconds to keep the connection alive to get around any browser/device limitations regarding inactivity. And I have confirmed via logging that this works fine until things disconnect on their own.
Any insight or suggestions is greatly appreciated!
What are the steps to reproduce the issue?
Http:
- Have a simple endpoint on a worker function that accepts a POST request and returns the same value back
- Start the worker locally using wrangler (exact command I was using last is
wrangler dev --port 7000 --remote --ip 192.168.1.112
) - Make a request to the worker via postman or other tool and observe it working correctly based on it’s response
- Now do nothing with the worker for like 20-30 minutes and try again, this time the request should fail with a connection error even though in the terminal where u ran the wrangler command you will continue to see the local server running
WebSockets:
- Repeat the above steps with a wrangler function that has a web socket based endpoint and which returns the same message sent to it as a response
- Set up a pinging mechanism so that the connection is maintained, send a dummy message from the server and respond to it from the client every 30 seconds on an interval
- Send a message and confirm the correct response is returned.
- Wait a few minutes while doing nothing with the worker
- Send another message, observe the error since u are no longer connected