Follow-up: host.go thread-safety, config validation, and targeted P2P tests after PR #6#8
Merged
Conversation
…age signing tests Agent-Logs-Url: https://github.com/danielsobrado/P2P-Market-Data/sessions/c91201de-cc7f-4b29-936f-c34925b89896 Co-authored-by: danielsobrado <35833752+danielsobrado@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add thread-safety and testing improvements after PR #6
Follow-up: host.go thread-safety, config validation, and targeted P2P tests after PR #6
Mar 27, 2026
danielsobrado
approved these changes
Mar 27, 2026
There was a problem hiding this comment.
Pull request overview
Follow-up to PR #6 to harden P2P host lifecycle/thread-safety, add targeted tests for connection accounting and message signing payload integrity, and fix pkg/data build issues that previously blocked test compilation.
Changes:
- Add focused unit tests for peer connection accounting idempotency and
GetConnectedPeersconsistency. - Add unit tests verifying
Message.MarshalWithoutSignature()excludesSignatureand covers integrity-sensitive fields. - Fix
pkg/databuild errors by correcting anerrredeclaration and removing a duplicate/incorrectGetDataSourcesimplementation. - Improve
pkg/p2p/host/host.golifecycle safety (running-state lock usage, double-start guard, safer shutdown sequencing, port range validation).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/peer/connection_test.go | Adds tests ensuring connect/disconnect handlers keep connCount consistent and idempotent. |
| pkg/p2p/message/message_test.go | Adds tests asserting the signed payload excludes signature and changes when integrity fields change. |
| pkg/p2p/host/host.go | Tightens lifecycle/thread-safety around running/shutdown and improves P2P port validation. |
| pkg/data/repository.go | Fixes compilation issues (err redeclare) and removes duplicate/incorrect GetDataSources. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #6 left three gaps:
pkg/p2p/host/host.gohad no thread-safety fixes, connection accounting and message signing behavior had no tests, and two pre-existing build errors inpkg/datablocked test compilation.pkg/data/repository.go— build fixes:=redeclaration onerr(line 416) →=GetDataSourcesmethod removed; the correct implementation (queriesdata_sourcesviar.pool) already existed inmodels.go; the duplicate queriedpeerswith wrong columnspkg/p2p/host/host.go— thread-safety & lifecycleIsRunning(): was readingh.runningwithout any lock — data raceStart(): no guard against double-start; returns error if already runningStop(): setsh.running = falseunder lock beforeclose(h.shutdown), eliminating the double-close risk; removes the redundant second lock-acquire at the endStart(): replaced direct mutation ofh.status.IsReady/UpdatedAt(bypassing theStatusstruct's own mutex) withh.status.UpdateStatus(...)validateP2PConfig: removed dangling// TODO: Fails herecomment block; added port range check (1–65535)pkg/peer/connection_test.go— connection accounting testsSix tests covering: single connect/disconnect, repeated connect events don't drift count above 1, repeated disconnect events don't decrement below 0, multiple peers tracked independently, reconnect cycle, and
GetConnectedPeersconsistency.pkg/p2p/message/message_test.go— message signing testsEight tests verifying:
MarshalWithoutSignatureexcludes thesignaturefield; all integrity-sensitive fields (type,version,id,timestamp,sender_id,data) are present in the signed payload; changingVersion,ID, orTimestampindependently produces a different payload; changing onlySignaturedoes not.Original prompt
Create the next follow-up implementation pull request for repository
danielsobrado/P2P-Market-Dataafter merged PR #6.Reference PR: #6
This follow-up PR should address the remaining likely gaps after PR #6, keeping scope focused and reviewable.
Primary goals
pkg/p2p/host/host.gothread-safety and lifecycle/config-validation improvements that were previously identified but not implemented in PR Fix script lifecycle, P2P accounting, migration safety, and frontend state refresh #6.Scope
Likely files include:
pkg/p2p/host/host.gopkg/peer/connection.gopkg/p2p/message/message.goRequired implementation work
A. Host lifecycle / thread-safety / config validation
pkg/p2p/host/host.gofor obvious thread-safety issues around running-state access and lifecycle transitions.B. Add missing targeted tests
Add focused tests for peer connection/accounting behavior.
Add focused tests for message signing/integrity behavior.
C. Optional small connection-status consistency fix
Acceptance criteria
pkg/p2p/host/host.gois updated if relevant issues are confirmed.Important
This PR should be a real implementation PR, not a planning-only PR.
The following is the prior conversation context from the user's chat exploration (may be truncated):
Assistant: Yes — PR #4 is already merged.
PR #4 status
https://github.com/danielsobrado/P2P-Market-Data/pull/4danielsobradoCurrent overall status
What’s still pending
From the PR metadata for #4:
So the remaining pending item is:
Verify whether PRs #3 and #4 actually included the intended fixes
Because a merged PR with 0 changed files strongly suggests at least PR #4 did not implement the requested changes.
Short answer
If you want, I can next inspect what PR #3 actually changed and compare it against the planned fixes.
User: Do that
Assistant: I checked PRs #3 and #4.
Result
Both PRs appear to have contained only a single commit named “Initial plan” and no changed files were returned for either PR.
That means the merged PRs likely did not implement the fixes.
PR-by-PR
PR #3
97c9f93f19a5bef303e1873136ac3a45611654eeComparison to intended scope
PR #3 was supposed to cover:
FatalAssessment: not implemented in the PR data I could inspect.
PR #4
556da9b61288cad8c8d381420f143b598ea36363changed_files: 0Comparison to intended scope
PR #4 was supposed to cover:
Assessment: also not implemented in the PR data I could inspect.
Bottom line
Yes, there is still major pending work.
Even though PRs #3 and #4 were merged, the available repository data indicate...
This pull request was created from Copilot chat.
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.