Skip to content

Forget abandoned results and lock shared state - #687

Open
alexander-akhmetov wants to merge 1 commit into
mainfrom
clean-up-abandoned-results
Open

Forget abandoned results and lock shared state#687
alexander-akhmetov wants to merge 1 commit into
mainfrom
clean-up-abandoned-results

Conversation

@alexander-akhmetov

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI lite review requested due to automatic review settings August 23, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.
  • Telegram now locks access to _results and _update_handlers, snapshots handler lists during dispatch, and forgets all in-flight results on stop().
  • The default files_directory is created/tightened to 0700 when possible; docs/tests updated accordingly (and legacy pylintrc removed).
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.

Comment thread telegram/client.py
return

self.files_directory.chmod(0o700)
except OSError:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants