-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure socket closes #4879
Ensure socket closes #4879
Conversation
Warning Rate limit exceeded@kaixi-wang has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 1 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes involve modifications to the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
fiftyone/service/ipc.py (1)
112-115
: Excellent use of context manager for socket handlingThe implementation of the context manager (
with
statement) for socket handling is a significant improvement. It ensures that the socket is properly closed after use, addressing the ResourceWarning issue mentioned in the PR objectives. This change follows Python best practices for resource management and maintains the existing functionality.Consider adding explicit error handling within the context manager to manage potential network-related exceptions. Here's a suggested improvement:
def send_request(port, message): try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect(("localhost", port)) pickle.dump(message, s.makefile("wb")) return pickle.load(s.makefile("rb")) except (socket.error, pickle.PickleError) as e: # Log the error or handle it as appropriate for your application raise ConnectionError(f"Failed to communicate with IPC server: {e}")This addition will provide more informative error messages and allow for graceful error handling in the calling code.
tests/ipc_tests.py (1)
126-150
: LGTM: Well-structured test for socket closure on exception.This test function effectively verifies that the socket is properly closed when an exception occurs during
send_request
. It aligns well with the PR objective and uses mocking appropriately to simulate the behavior without actual network operations.A minor suggestion for improvement:
Consider adding an assertion to verify that
mock_socket_instance.close()
is called. This would provide an extra layer of certainty that the socket is explicitly closed. You can add this assertion just before the existing assertions:mock_socket_instance.close.assert_called_once()This addition would make the test even more robust in ensuring proper resource management.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
- fiftyone/service/ipc.py (1 hunks)
- requirements/test.txt (1 hunks)
- tests/ipc_tests.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
- requirements/test.txt
🔇 Additional comments (2)
tests/ipc_tests.py (2)
16-18
: LGTM: New imports are appropriate for the added test.The new imports (unittest, BytesIO, and MagicMock) are correctly added and are necessary for the new test function. These are standard Python libraries, which is good for maintaining minimal external dependencies.
Line range hint
1-150
: Summary: Excellent addition to improve test coverage for socket closure.The changes in this file effectively address the PR objective of ensuring proper socket closure. The new test function
test_socket_closes_on_exception
is well-implemented and uses appropriate mocking techniques to verify the behavior without actual network operations.Key points:
- The new test aligns perfectly with the goal of eliminating ResourceWarnings due to unclosed sockets.
- The implementation follows good testing practices, including the use of mocking and specific assertions.
- Existing tests remain unchanged, maintaining the integrity of previous test coverage.
These changes contribute to the overall robustness of the IPC functionality in FiftyOne by ensuring that edge cases related to exception handling and resource management are properly tested.
requirements/test.txt
Outdated
itsdangerous==2.0.1 | ||
werkzeug==3.0.3 | ||
werkzeug==2.0.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attempting to run any tests locally with python v3.9 fails with
ImportError: cannot import name 'BaseResponse' from 'werkzeug.wrappers' (/Users/kacey/.pyenv/versions/3.9.14/envs/fo/lib/python3.9/site-packages/werkzeug/wrappers/__init__.py)
unless 2.0.3 specified (with open3d 0.16.1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comment otherwise LGTM :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice fix ✨
* ensure socket closes * fmt * fix test dependency * fix test dependency * fix open3d dep * try resolve dep
What changes are proposed in this pull request?
How is this patch tested? If it is not, please explain why.
Release Notes
Is this a user-facing change that should be mentioned in the release notes?
notes for FiftyOne users.
(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)
What areas of FiftyOne does this PR affect?
fiftyone
Python library changesSummary by CodeRabbit
New Features
Bug Fixes
Chores
open3d
package in the testing requirements.werkzeug
package in the testing requirements.