Skip to content

fix: 修复 BlazeSocket 连接关闭时的 SSL 错误 #123

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

Merged
merged 1 commit into from
Apr 13, 2025
Merged

Conversation

g1331
Copy link
Owner

@g1331 g1331 commented Apr 13, 2025

好的,这是翻译成中文的 pull request 总结:

Sourcery 总结

通过在套接字关闭期间添加强大的异常处理,改进 BlazeSocket 连接的错误处理。

Bug 修复:

  • 处理关闭 Blaze 套接字连接时的 SSL 错误和意外异常,以防止潜在的应用程序崩溃

增强功能:

  • 添加连接关闭错误的日志记录,以便更好地了解与网络相关的问题
Original summary in English

Summary by Sourcery

Improve error handling for BlazeSocket connections by adding robust exception handling during socket closure

Bug Fixes:

  • Handle SSL errors and unexpected exceptions when closing Blaze socket connections to prevent potential application crashes

Enhancements:

  • Add logging for connection closure errors to provide better visibility into network-related issues

问题描述:
在关闭 BlazeSocket 连接时出现 SSL 错误:
"ssl.SSLError: [SSL: APPLICATION_DATA_AFTER_CLOSE_NOTIFY] application data after close notify"

解决方案:
1. 在 BlazeSocket.py 中添加 SSL 错误处理
2. 在 BlazeClient.py 中为连接管理方法添加异常处理
3. 改进 bf_utils.py 中的错误处理逻辑

这些更改使系统能够优雅地处理 SSL 连接关闭时的错误,防止应用程序崩溃。
Copy link
Contributor

sourcery-ai bot commented Apr 13, 2025

Sourcery 评审指南

此 pull request 在 BlazeClientBlazeSocketbf_utils 中添加了强大的 socket 关闭期间的错误处理,以防止由 SSL 错误或其他异常引起的崩溃。它包括针对 ssl.SSLError 的特定处理,并提供日志记录以帮助调试。

BlazeSocket 的更新类图

classDiagram
  class BlazeSocket {
    -host: str
    -port: int
    -ssl: bool
    -reader: asyncio.StreamReader
    -writer: asyncio.StreamWriter
    -session: aiohttp.ClientSession
    -connect: bool
    +__init__(host: str, port: int, ssl: bool = True)
    +send(packet: bytes) bytes
    +connect_to_server()
    +close()
    +keepalive()
  }
  note for BlazeSocket "Added try-except block to handle SSL errors during socket closure"
Loading

文件级别变更

变更 详情 文件
添加了 socket 关闭的错误处理,以防止由于断开连接期间的 SSL 错误或其他异常引起的崩溃。
  • client.close() 调用包装在 BlazeClient 方法(get_socket_for_pidclose_allremove_client)的 try-except 块中,以捕获 socket 关闭期间的异常。
  • BlazeClient 中添加了 socket 关闭期间发生的错误的日志记录。
  • self.writer.close()self.writer.wait_closed() 调用包装在 BlazeSocket.close() 的 try-except 块中,以捕获 ssl.SSLError 和其他异常。
  • BlazeSocket.close() 中添加了 SSL 错误(特别是 APPLICATION_DATA_AFTER_CLOSE_NOTIFY)的日志记录作为警告,因为它们被认为是可忽略的。
  • BlazeSocket.close() 中添加了 socket 关闭期间发生的其他错误的日志记录。
  • blaze_socket.close() 调用包装在 get_player_list 的 try-except 块中,以捕获 socket 关闭期间的异常。
  • get_player_list 中添加了 socket 关闭期间发生的错误的日志记录。
utils/bf1/blaze/BlazeClient.py
utils/bf1/blaze/BlazeSocket.py
utils/bf1/bf_utils.py

提示和命令

与 Sourcery 互动

  • 触发新的审查: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 要求 Sourcery 从审查评论创建一个 issue,方法是回复它。您也可以回复审查评论并使用 @sourcery-ai issue 从该评论创建一个 issue。
  • 生成 pull request 标题: 在 pull request 标题中的任何位置写入 @sourcery-ai 以随时生成标题。您也可以在 pull request 上评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文中的任何位置写入 @sourcery-ai summary 以随时在您想要的位置生成 PR 摘要。您也可以在 pull request 上评论 @sourcery-ai summary 以随时(重新)生成摘要。
  • 生成评审指南: 在 pull request 上评论 @sourcery-ai guide 以随时(重新)生成评审指南。
  • 解决所有 Sourcery 评论: 在 pull request 上评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经解决了所有评论并且不想再看到它们,这将非常有用。
  • 驳回所有 Sourcery 审查: 在 pull request 上评论 @sourcery-ai dismiss 以驳回所有现有的 Sourcery 审查。如果您想重新开始新的审查,这将特别有用 - 不要忘记评论 @sourcery-ai review 以触发新的审查!
  • 为 issue 生成行动计划: 在 issue 上评论 @sourcery-ai plan 以为其生成行动计划。

自定义您的体验

访问您的 仪表板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、评审指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获得帮助

Original review guide in English

Reviewer's Guide by Sourcery

This pull request adds robust error handling during socket closure in BlazeClient, BlazeSocket, and bf_utils to prevent crashes caused by SSL errors or other exceptions. It includes specific handling for ssl.SSLError with logging to aid in debugging.

Updated class diagram for BlazeSocket

classDiagram
  class BlazeSocket {
    -host: str
    -port: int
    -ssl: bool
    -reader: asyncio.StreamReader
    -writer: asyncio.StreamWriter
    -session: aiohttp.ClientSession
    -connect: bool
    +__init__(host: str, port: int, ssl: bool = True)
    +send(packet: bytes) bytes
    +connect_to_server()
    +close()
    +keepalive()
  }
  note for BlazeSocket "Added try-except block to handle SSL errors during socket closure"
Loading

File-Level Changes

Change Details Files
Added error handling for socket closure to prevent crashes due to SSL errors or other exceptions during disconnection.
  • Wrapped the client.close() calls in BlazeClient methods (get_socket_for_pid, close_all, remove_client) in try-except blocks to catch exceptions during socket closure.
  • Added logging of errors that occur during socket closure in BlazeClient.
  • Wrapped the self.writer.close() and self.writer.wait_closed() calls in BlazeSocket.close() in a try-except block to catch ssl.SSLError and other exceptions.
  • Added logging of SSL errors (specifically APPLICATION_DATA_AFTER_CLOSE_NOTIFY) as warnings in BlazeSocket.close() since they are considered ignorable.
  • Added logging of other errors that occur during socket closure in BlazeSocket.close().
  • Wrapped the blaze_socket.close() call in get_player_list in a try-except block to catch exceptions during socket closure.
  • Added logging of errors that occur during socket closure in get_player_list.
utils/bf1/blaze/BlazeClient.py
utils/bf1/blaze/BlazeSocket.py
utils/bf1/bf_utils.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

@g1331 - 我已经查看了你的更改 - 这里有一些反馈:

总体评论

  • 考虑创建一个共享的实用程序函数来处理 try-except-finally 块,以避免重复。
以下是我在审查期间查看的内容
  • 🟢 一般问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对于开源是免费的 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English

Hey @g1331 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider creating a shared utility function to handle the try-except-finally block for closing connections to avoid repetition.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@g1331 g1331 merged commit ed46a02 into v3 Apr 13, 2025
5 checks passed
@g1331 g1331 deleted the fix/bf1/blaze branch April 18, 2025 01:57
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.

1 participant