Skip to content

Auto-rebuild listener on fatal socket errors and refactor listener creation#44

Open
CypherPotato wants to merge 1 commit into
mainfrom
codex/read-issue-43-and-its-derivation
Open

Auto-rebuild listener on fatal socket errors and refactor listener creation#44
CypherPotato wants to merge 1 commit into
mainfrom
codex/read-issue-43-and-its-derivation

Conversation

@CypherPotato
Copy link
Copy Markdown
Member

Motivation

  • Improve robustness of the TCP listener by detecting fatal socket errors during accept and automatically rebuilding the listening socket so the host can recover without full process restart.
  • Reduce duplication and make socket configuration explicit by centralizing listener creation and options.

Description

  • Replace readonly _listener with a mutable socket and introduce CreateListenerSocket() to centralize socket construction and options previously in ConfigureListenerSocket().
  • On Start() dispose the previous listener (if any) and recreate a fresh listener, then bind and listen before starting the accept pool.
  • Add _listenerRestarting flag and logic in StartAccept(), OnAcceptCompleted() and ProcessAcceptInline() to detect fatal SocketError values via IsListenerFatalError() and trigger RebuildListenerAsync() which retries creating/binding a new listener and restarts accept loops.
  • Return negative rearm values from ProcessAcceptInline() to indicate caller should stop rearming and handle restart scenarios, and adjust accept-queueing logic accordingly.

Testing

  • No automated tests were executed as part of this change.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e5d53d365

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +273 to +274
catch (SocketException) {
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Dispose failed rebuilt listener before retry loop

When CreateListenerSocket()/Bind/Listen throws during RebuildListenerAsync, the catch (SocketException) block swallows the exception and immediately retries without disposing the just-created newListener. In a persistent failure (e.g., endpoint temporarily unavailable), this leaks one socket handle every 250ms, which can exhaust file descriptors and prevent the host from recovering.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant