Repository navigation
Conversation
A command that waits on an upstream which never answers holds its request open until the client gives up; nothing on the server ends it. OPENBB_COMMAND_TIMEOUT sets a deadline in seconds for every command and OPENBB_COMMAND_TIMEOUT_<PROVIDER> overrides it for one provider. Unset, as by default, commands run as before. Past the deadline the command is cancelled at its next await and raises TimeoutError naming the provider; a TimeoutError the command raises itself passes through unchanged. Values are read once at import, so a value that is not a positive number stops the server at startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Problem
StaticCommandRunner._commandawaits a command with no limit. If a command waits on an upstream that never answers, its request stays open until the client gives up, and nothing on the server ends the command.Change
Two optional environment variables, read through
Envlike the otherOPENBB_*settings:OPENBB_COMMAND_TIMEOUTsets a deadline in seconds for every command.OPENBB_COMMAND_TIMEOUT_<PROVIDER>overrides it for one provider. The provider comes fromprovider_choices, else from the command's top-level package with theopenbb_prefix dropped.Unset, which is the default, commands run exactly as before. With a deadline,
_commandruns the command underasyncio.wait_for. Past the deadline, the command is cancelled at its next await and raisesTimeoutError("The <provider> provider did not answer within <n> seconds."). ATimeoutErrorthat the command raises itself passes through unchanged. The values are read once at import, so a value that is not a positive number stops the server at startup.Why this is written against
developand not on top of #7749. #7749 runs each provider's commands on its own event loop. The deadline doesn't depend on it: ondevelop's runner,wait_foralready ends any command that is waiting on I/O, which is the hang this PR addresses. What #7749 adds is timeliness for CPU-bound commands. Without it, such a command blocks the server loop, so its 504 can only go out once the command reaches an await. With #7749, the server loop stays free and the 504 goes out on time. The two PRs touch the same lines of_command. Whichever merges second needs a small rebase: the deadline then wraps the future returned from the provider's loop. I'll do that rebase.Tests
tests/test_env.py: unset or empty gives no deadlines; a default plus a per-provider override parse correctly;abc,0,-5andnanraiseValueErrornaming the variable, for both the default and a per-provider name.tests/app/test_command_runner.py: a command past its provider's 0.2 s deadline is cancelled (it seesCancelledError) and raises aTimeoutErrornaming the provider in under 5 s. A separate test checks that a command's ownTimeoutError("EIA timed out")passes through unchanged.All seven new tests fail without the change. The pass-through test is a guard; without the change it fails only because the deadline setting doesn't exist yet. The two files pass 75/75, and
openbb_platform/core/testspasses 2,255 with 16 skipped (Python 3.12).Results from a deployment
OpenBQ's Docker image runs this deadline on top of #7749's per-provider loops, with deployment-specific names: a 55 s default and 90 s for CFTC, whose forex
swap_tradestakes about 70 s. Here that isOPENBB_COMMAND_TIMEOUT=55andOPENBB_COMMAND_TIMEOUT_CFTC=90./widgets.jsonanswered every one-second poll in at most 0.03 s.OPENBB_COMMAND_TIMEOUT=55and the same 70 s command:500 Unexpected Error -> TimeoutError -> The slowfake provider did not answer within 55 seconds., and/widgets.jsonanswers all 55 polls in at most 0.012 s.TimeoutErrorto 504, the same request answers 504 at 55.3 s, and/widgets.jsonanswers in at most 0.007 s.Not included
developit keeps the server loop busy until then (see feat(core): run each provider's commands on its own event loop #7749).TimeoutErroris a 500.🤖 Generated with Claude Code