Skip to content

Fix LAN network cleanup state for stability#959

Open
calcitem wants to merge 1 commit into
masterfrom
codex/fix-lan-vs-lan-network-battle-bugs-rz11c1
Open

Fix LAN network cleanup state for stability#959
calcitem wants to merge 1 commit into
masterfrom
codex/fix-lan-vs-lan-network-battle-bugs-rz11c1

Conversation

@calcitem
Copy link
Copy Markdown
Owner

Summary

  • keep the LAN network service alive after disconnects by resetting its sockets instead of marking it permanently disposed
  • reset handshake completers, counters, and connection metadata whenever the service is torn down so stale state does not leak between sessions

Testing

  • ./format.sh s (fails locally because dart is unavailable)

https://chatgpt.com/codex/tasks/task_e_68eb6e4e99288320a2c3959ef52108af

@github-actions
Copy link
Copy Markdown

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

Unrecognized words (27)
Ctl
CXXFLAGS
deinitialize
depthext
edt
efmr
evals
ewt
fal
fmr
gameplay
glm
Hms
imbalanced
kimi
MMdd
moonshotai
movetime
nmove
occ
sid
STEB
subtag
toremove
tru
workaround
zhiqi
These words are not needed and should be removed Blabla bmf NMove NOCOLOR SId Subtags

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the git@github.com:calcitem/Sanmill.git repository
on the codex/fix-lan-vs-lan-network-battle-bugs-rz11c1 branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/main/apply.pl' |
perl - 'https://github.com/calcitem/Sanmill/actions/runs/18441878547/attempts/1' &&
git commit -m 'Update check-spelling metadata'

OR

To have the bot accept them for you, comment in the PR quoting the following line:
@check-spelling-bot apply updates.

Forbidden patterns 🙅 (2)

In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves.

These forbidden patterns matched content:

s.b. into

\bin to\b

Pattern

\b[Nn]o[nt][- ]existent\b
Errors and Warnings ❌ (2)

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors and Warnings Count
❌ forbidden-pattern 2
⚠️ ignored-expect-variant 3

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

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.

ℹ️ 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

Comment on lines 1000 to +1021

_messageQueue.clear();
_isProcessingMessages = false;
if (_protocolHandshakeCompleter != null &&
!_protocolHandshakeCompleter!.isCompleted) {
_protocolHandshakeCompleter!.complete(false);
}
_protocolHandshakeCompleter = null;
_heartbeatStarted = false;
_isReconnecting = false;
_messagesSent = 0;
_messagesReceived = 0;
_reconnectAttempts = 0;
_opponentAddress = null;
_opponentPort = null;
_lastConnectionTime = null;

logger.i("$_logTag Network disposed");
if (!markDisposed) {
_disposed = false;
logger.i("$_logTag Network connection reset");
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 Guard _disposeInternals against re-entrancy

The new _disposeInternals({bool markDisposed = true}) skips setting _disposed when markDisposed is false and immediately resets it to false at the end. _handleDisconnection now calls this method with markDisposed: false, so during teardown the service never enters a disposed state. Socket listeners (onError, onDone) and heartbeat timers check _disposed before invoking _handleDisconnection, meaning multiple callbacks that fire during the same disconnect will all pass the check and re-enter the teardown logic. This can invoke onDisconnected and UI updates multiple times and race concurrent clean‑ups. To keep the service reusable while still preventing repeated work, _disposeInternals should temporarily mark _disposed true while cleaning up and only set it back to false after the reset completes.

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