Skip to content

Fix Linux TCP listener lifecycle and idle disconnect detection - #3327

Closed
ace-code-0 wants to merge 3 commits into
Pryaxis:general-develfrom
ace-code-0:fix/linux-tcp-listener-lifecycle
Closed

ace-code-0 wants to merge 3 commits into
Pryaxis:general-develfrom
ace-code-0:fix/linux-tcp-listener-lifecycle

Conversation

@ace-code-0

@ace-code-0 ace-code-0 commented Nov 13, 2026 •

Copy link
Copy Markdown

Changes

  • Prevent stale accept loops from closing newer listeners.
  • Stop blocked accepts when listening ends.
  • Detect idle TCP disconnects using Socket.Poll, allowing EOF handling and slot cleanup.

Related issue

#3321

Validation

  • .NET 9 Release build: passed.
  • Reproduced missing listener and 27 CLOSE_WAIT sockets.
  • Patched runtime testing pending.

AI Assistance

Model: GPT-6 (ChatGPT)
Reasoning effort: High
Scope: Debugging, implementation, and review.
Greptile finding addressed in ecf4ffc.

@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous listener-stop crash is addressed.

Summary

Fixes the remaining listener-stop race.

  • Idle Linux client disconnects now reach player-slot cleanup.
  • Each Linux listener run stops without disrupting its replacement.

Reviews (2) · Last reviewed commit: "fix: handle listener shutdown race" · Reviewed by Greptile

Comment on lines +232 to +239
catch (ObjectDisposedException)
{
break;
}
catch (SocketException)
{
break;
}

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.

P1 Stopping listening can crash server

StopListening() can stop the listener after ListenLoop releases _listenerLock but before it calls AcceptTcpClient(). Calling AcceptTcpClient() on a stopped listener throws InvalidOperationException, which neither catch handles. The old blanket catch covered this case. The exception now escapes the thread-pool worker and can terminate the server.

Catch InvalidOperationException for this stop race and exit the loop.

@hakusaro

Copy link
Copy Markdown
Member

@ace-code-0 i will check in under 120 minutes

@hakusaro

Copy link
Copy Markdown
Member

Thoughts on greptile?

@hakusaro

Copy link
Copy Markdown
Member

@ace-code-0 please see updated requirements published to discord as of 03:15 JST. If these apply to this PR, please take action accordingly. If you wrote these yourself without AI, please feel free to ignore this.

If you are submitting PRs to TShock or other projects and use AI or LLM-generation please state clearly in your PR the model, effort, and other settings used. Please do not omit these notes. If you submit an AI generated PR the level of effort you go to must be higher than normal, for example, we expect you to have fully tested your code and have already done adversarial AI reviews against your code and to respond promptly to all greptile review comments and address them. The latter requirements do not apply to entirely human written code.

@ace-code-0

Copy link
Copy Markdown
Author

Thoughts on greptile?

The issue was addressed in ecf4ffc. Greptile's latest review confirms the fix (5/5).

@hakusaro

hakusaro commented Nov 14, 2026 via email

Copy link
Copy Markdown
Member

@hakusaro

Copy link
Copy Markdown
Member

Incredibly amusing. argo@fluctlight.net is the email.

@ace-code-0

Copy link
Copy Markdown
Author

Sent the reproduction PoC (test_tshock.py) to argo@fluctlight.net.

@ace-code-0

Copy link
Copy Markdown
Author

Hi, any updates on the PoC validation? Let me know if any further changes or testing are needed.

@defonion

Copy link
Copy Markdown

I ran an independent validation of this PR (TShock 6.2.1 base b25b3e5, linux-x64, CI-style build, -maxplayers 8):

Code notes: unlike #3325 this PR has no TCP keepalive and no IOException handling in ReadCallback, and the new block uses spaces instead of tabs (CONTRIBUTING asks for tabs).

Details and table: Pryaxis/TSAPI#284 (comment).

@ace-code-0 ace-code-0 closed this Nov 28, 2026
@ace-code-0

Copy link
Copy Markdown
Author

Closing in favor of #3325 and Pryaxis/TSAPI#284, which together passed independent runtime validation.

Thanks @defonion for the testing and feedback.

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.

3 participants