Skip to content

Conversation

sameh-farouk
Copy link
Member

@sameh-farouk sameh-farouk commented Aug 12, 2025

Note: This branch is based on another feature branch(#1391); to make things simpler for reviewing, I'm choosing that branch as the merge target so you can see only the relevant changes. After the first branch gets merged, I'll set development as the target branch for this PR before merging.

Description

This PR focuses on lifecycle stability and observability, introduces clean, context-driven shutdown for the Peer, stronger relay connection error handling, and improved logging/observability. It also adds a goleak integration test and updates the docs to reflect the new lifecycle.

  • Deterministic shutdown: Context shutdown simplifies lifecycle and prevents leaks.
  • Resilient connectivity: Cancelable dialing and safer error handling and shutdown patterns avoid hangs, races, and panics during relay failures or shutdown.
  • Better observability: Structured logs for connect/stop paths and shutdown exits.

Changes

  • rmb-sdk-go/peer/peer.go
    • Added parent-context watcher to automatically trigger internal shutdown when ctx.Done() fires, ensuring deterministic, leak-free teardown.
    • Improved goroutine lifecycle via WaitGroup and structured exit logging around the processing loop.
    • Net effect: Peer stops via context cancellation only; internal routines exit promptly.
  • rmb-sdk-go/peer/connection.go
    • Made dialing/retry loops context-aware (cancelable DialContext, prompt exit on shutdown).
    • Hardened error handling paths during connect/stop and added richer debug logging.
    • Removed unsafe shutdown patterns to avoid races or stuck goroutines.
  • rmb-sdk-go/peer/leak_integration_test.go (new)
    • Added goleak-based integration test ensuring no goroutine leaks after context-driven shutdown.
  • rmb-sdk-go/peer/README.md
    • Updated examples to use context.WithCancel and clearly document context-only shutdown behavior.

Related Issues

#1408

Checklist

  • Tests included
  • Build pass
  • Documentation
  • Code format and docstring

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