Skip to content

fix: avoid InvalidStateError on mid-stream platform websocket disconnect#867

Merged
vdusek merged 2 commits intomasterfrom
fix/event-manager-ws-disconnect-invalid-state
Apr 20, 2026
Merged

fix: avoid InvalidStateError on mid-stream platform websocket disconnect#867
vdusek merged 2 commits intomasterfrom
fix/event-manager-ws-disconnect-invalid-state

Conversation

@vdusek
Copy link
Copy Markdown
Contributor

@vdusek vdusek commented Apr 20, 2026

Summary

Guard set_result(False) in ApifyEventManager._process_platform_messages with a done() check. Previously, a websocket disconnect after a successful connect would try to re-resolve the already-resolved _connected_to_platform_websocket future, raising InvalidStateError and masking the original ConnectionClosedError in logs.

Adds a regression test that forces a mid-stream abnormal close from the server and asserts the background task does not surface InvalidStateError.

Guard `set_result(False)` in `_process_platform_messages` with a `done()`
check so a disconnect after a successful connect no longer tries to
re-resolve the already-resolved `_connected_to_platform_websocket`
future. This preserves the original `ConnectionClosedError` in logs
instead of masking it with `InvalidStateError`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Apr 20, 2026
@vdusek vdusek self-assigned this Apr 20, 2026
@github-actions github-actions Bot added this to the 139th sprint - Tooling team milestone Apr 20, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Apr 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.64%. Comparing base (16bf07d) to head (22b185d).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #867   +/-   ##
=======================================
  Coverage   86.64%   86.64%           
=======================================
  Files          48       48           
  Lines        2920     2920           
=======================================
  Hits         2530     2530           
  Misses        390      390           
Flag Coverage Δ
e2e 37.87% <0.00%> (ø)
integration 59.28% <0.00%> (ø)
unit 75.37% <100.00%> (+0.68%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek vdusek requested a review from Pijukatel April 20, 2026 11:41
Comment thread tests/unit/events/test_apify_event_manager.py
…ession

The test previously only asserted that the task did not raise
`InvalidStateError`, which is trivially satisfied if the disconnect path
was never taken. Inspect `caplog` to confirm a `ConnectionClosedError`
was actually logged by `_process_platform_messages`, so the regression
scenario is genuinely exercised.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vdusek vdusek merged commit 4dbbd3f into master Apr 20, 2026
31 checks passed
@vdusek vdusek deleted the fix/event-manager-ws-disconnect-invalid-state branch April 20, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants