fix: prevent Actor log-streaming thread from crashing on stream timeout#944
Draft
vdusek wants to merge 2 commits into
Draft
fix: prevent Actor log-streaming thread from crashing on stream timeout#944vdusek wants to merge 2 commits into
vdusek wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master apify/apify-sdk-python#944 +/- ##
==========================================
- Coverage 94.56% 94.51% -0.06%
==========================================
Files 48 48
Lines 5119 5127 +8
==========================================
+ Hits 4841 4846 +5
- Misses 278 281 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After a successful
ActorClient.call(), the background log-streaming thread could crash with an uncaughtimpit.TimeoutException, printing a traceback even though the run finished fine. Reported in #945.Root cause
StreamedLogrequested the log stream with a bounded 30s timeout. impit applies itstimeoutto the whole request, including the streamed response body (not just connect / read-idle), so any run that streamed logs for longer than the timeout trippedimpit.TimeoutExceptionmid-stream, and the sync thread had no handler. The async twin caught it but logged a spuriousERROR+ traceback. A bounded value could never be large enough anyway: every timeout tier is capped atDEFAULT_TIMEOUT_MAX(360s), so evenlongwould truncate a run past ~6 minutes.Fix
no_timeout(the only tier above the 360s cap; maps to impit's ~24h ceiling), so it streams until the server closes it with EOF at run finish. The JS client takes the same approach, setting no body timeout on the log stream.impit.TimeoutExceptionas an expected terminal condition in both the sync and async paths (end quietly instead of crashing / error-logging), while still logging any other failure.Known limitation
A parked synchronous
iter_bytes()read cannot be interrupted from another thread, so withno_timeout,StreamedLog.stop()on a stream that is still running but momentarily silent now waits for the next chunk or EOF rather than the old 30s bound. TheActorClient.call()path is unaffected, since run finish sends EOF and the stream ends promptly. This matches the JS client's behavior. Making manualstop()responsive for silent/standby streams would need a reconnect/resume mechanism, which the log API doesn't currently support (no resume offset, and it replays the whole log on reconnect).Behavior note
On long-running async redirection, the
ERROR: Log redirection stopped due to unexpected error:line that previously fired on the 360s timeout no longer fires. The message text, its level, and the logger name are unchanged; it now fires only on genuine, non-timeout errors.