Anže
04/09/2026, 11:34 AM11:22:03.658 | WARNING | prefect.events.clients - Unable to connect to '<wss://api.prefect.cloud/api/accounts/act-nmbr-123/workspaces/wroks-nm-123/events/in>'. Please check your network settings to ensure websocket connections to the API are allowed. Otherwise event data (including task run data) may be lost. Reason: timed out during opening handshake. Set PREFECT_DEBUG_MODE=1 to see the full error.
The wss url matches what we can see in the prefect.io dashboard.
Even though the queue starts growing prefect jobs are still getting started correctly and there is no degradation. Really the only problem is that the service container that runs:
/bin/sh,-c,pip install prefect-aws && prefect worker start --pool our-workpool --type ecs
will run out of memory because the memory consumption seems to be growing with the queue.Marvin
04/09/2026, 11:34 AMMarvin
04/09/2026, 11:37 AMPREFECT_EVENTS_WORKER_MAX_QUEUE_SIZE=50000
Note: if the connection stays down, older event data may be dropped once the cap is hit, but your worker will remain healthy.
- If you can accept losing ECS crash detection/log forwarding temporarily, disable the ECS observer to stop producing/queuing those events:
PREFECT_INTEGRATIONS_AWS_ECS_OBSERVER_ENABLED=false
Work dispatch will continue; you’ll just lose ECS crash observability until re-enabled.
- Bake prefect-aws into your image instead of pip installing on boot to reduce container churn:
# In your Dockerfile
RUN pip install prefect-aws
# Then just run:
prefect worker start --pool our-workpool --type ecs
How to fix the root cause (wss connectivity)
- Turn on debug to see the underlying socket/TLS/proxy error:
PREFECT_DEBUG_MODE=1
This will include the exception that is causing the handshake timeout.
- Verify egress:
- Allow outbound 443 to api.prefect.cloud.
- If you use a corporate proxy, ensure websocket upgrades are allowed and that Authorization headers are forwarded for websocket handshakes. If your proxy strips Authorization on upgrade, the connection will fail.
- If you must use a proxy, set appropriate env vars (HTTPS_PROXY/NO_PROXY). Consider adding api.prefect.cloud to NO_PROXY if the proxy blocks websockets.
- Sanity checks from the worker container:
- Confirm your API base is correct (used to derive the wss URL):
prefect config view | grep PREFECT_API_URL
- Quick TLS reachability check (not a websocket test, but useful):
curl -I <https://api.prefect.cloud/>
- If possible in your environment, temporarily test a simple websocket client against the events URL using your API key to confirm upgrades are permitted. If that’s not feasible, the PREFECT_DEBUG_MODE trace usually reveals the culprit (proxy reset, cert verification, etc.).
AWS/SQS specifics to review
- In CloudWatch for the SQS queue, check AgeOfOldestMessage: it should rise when you see the websocket warnings and then fall after a restart (when connectivity returns).
- Ensure the queue’s visibility timeout is comfortably larger than the observer’s processing window and network roundtrips (long polling is used, but this usually isn’t the limiting factor here).
Version info request
- Which versions are you on for prefect and prefect-aws? There have been improvements to the ECS observer and event clients in recent 3.x releases. Sharing:
- output of prefect version
- output of python -c "import prefect_aws, pkgutil;print(prefect_aws.__version__)"Marvin
04/09/2026, 11:37 AMAnže
04/09/2026, 11:45 AMMarvin
04/09/2026, 11:45 AMMarvin
04/09/2026, 11:47 AMPREFECT_DEBUG_MODE=1
Look for any “delete_message”/SQS-related exceptions in the worker logs.
- Verify SQS metrics in CloudWatch:
- NumberOfMessagesReceived vs NumberOfMessagesDeleted (they should track closely)
- AgeOfOldestMessage (will climb during backlogs)
- Confirm the task role attached to the worker has, at minimum, these permissions on the queue ARN:
- sqs:GetQueueUrl, sqs:ReceiveMessage, sqs:DeleteMessage, sqs:ChangeMessageVisibility
- Make sure you’re pointing at the intended queue:
PREFECT_INTEGRATIONS_AWS_ECS_OBSERVER_SQS_QUEUE_NAME=<your-queue>
PREFECT_INTEGRATIONS_AWS_ECS_OBSERVER_SQS_QUEUE_REGION=<region>
- If you need to keep the service stable while debugging the websocket/network issue:
- Cap the in-process event buffer so memory can’t grow unbounded:
PREFECT_EVENTS_WORKER_MAX_QUEUE_SIZE=50000
- If acceptable, temporarily disable the ECS observer to stop consuming/producing those events:
PREFECT_INTEGRATIONS_AWS_ECS_OBSERVER_ENABLED=false
- Optionally scale the worker service to 2+ tasks to increase SQS consumption while you investigate.
Notes on versions
- Your test across latest and 3.4.20 matches the implementation — the SQS deletion behavior has been consistent across those versions. The websocket warning you’re seeing is a known symptom of network/proxy issues (an example of the warning appearing in the wild: issue #16299), but the root cause in that ticket is different from yours.
If you can share:
- one “stuck” message body (redacted) from SQS,
- a snippet of logs with PREFECT_DEBUG_MODE=1 around the time the queue starts growing,
- and confirm the IAM policy on the worker task role,
…I can help pinpoint whether you’re hitting delete failures, processing gaps, or unrelated messages landing in the queue.