Forget abandoned results and lock shared state - #687
Open
alexander-akhmetov wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
telegram/client.py uses os.getuid() without handling platforms where it is unavailable (e.g., Windows), which can crash client construction.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens the library’s thread-safety and lifecycle handling by (1) forgetting AsyncResults that callers abandon (timeouts / shutdown), (2) guarding shared maps with locks, and (3) tightening default TDLib session directory permissions when using the implicit temp-dir-based path.
Changes:
AsyncResult.wait(timeout=...)now abandons timed-out results (client forgets them) and subsequent waits raise instead of blocking.Telegramnow locks access to_resultsand_update_handlers, snapshots handler lists during dispatch, and forgets all in-flight results onstop().- The default
files_directoryis created/tightened to0700when possible; docs/tests updated accordingly (and legacypylintrcremoved).
File summaries
| File | Description |
|---|---|
telegram/utils.py |
Marks timed-out AsyncResults as abandoned and forgets them via the client. |
telegram/client.py |
Adds locks for _results/handlers, implements _forget_result, clears results on stop, and restricts default files directory permissions. |
tests/test_utils.py |
Adds coverage for timeout abandonment and post-timeout wait() behavior. |
tests/test_telegram_methods.py |
Adds tests for handler snapshotting, result forgetting/reuse, stop() cleanup, and default files-directory permission behavior. |
README.md |
Updates usage example to reflect optional files_directory and safer default behavior. |
docs/source/tutorial.rst |
Documents the new default directory behavior, permission tightening, and warning conditions. |
docs/source/changelog.rst |
Records behavioral changes around timeouts, fixed IDs, directory permissions, and locking. |
tests/requirements.txt |
Removes types-pkg-resources from test requirements. |
pylintrc |
Removes the legacy pylint configuration file. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return | ||
|
|
||
| self.files_directory.chmod(0o700) | ||
| except OSError: |
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.
No description provided.