Skip to content

fix: harden accesspoint connection lifecycle#302

Merged
devgianlu merged 1 commit intodevgianlu:masterfrom
gjermundgaraba:fix/ap-connection-lifecycle
Apr 12, 2026
Merged

fix: harden accesspoint connection lifecycle#302
devgianlu merged 1 commit intodevgianlu:masterfrom
gjermundgaraba:fix/ap-connection-lifecycle

Conversation

@gjermundgaraba
Copy link
Copy Markdown
Contributor

I was seeing nil-pointer crashes and AP lifecycle issues in cliamp, and traced them to the access point close/reconnect flow being unsafe around early shutdown and concurrent I/O. In particular, the stop channels were only initialized inside connect(), so closing early could not reliably stop AP goroutines, and pongAckTicker could panic when it tried to close a nil connection.

Prevent panics and races during AP close/reconnect by:

  • Initializing stop channels in the constructor instead of on each connect
  • Adding a permanent closed state that rejects Send/Connect and makes Receive return a closed channel after Close
  • Using non-blocking stop signals to avoid blocking or leaked goroutines
  • Serializing connection close/stop checks behind proper locking helpers
  • Resetting the pong-ack deadline on reconnect to avoid false timeouts

I also found some similar behavior in dealer and mercury, but opening those as separate PRs (as per the contribution guidelines :))

Prevent panics and races during AP close/reconnect by:
- Initializing stop channels in the constructor instead of on each connect
- Adding a permanent closed state that rejects Send/Receive/Connect after Close
- Using non-blocking signal sends to avoid goroutine leaks
- Protecting conn access with proper locking (closeConn, isStopped helpers)
- Resetting pong-ack deadline on reconnect to avoid false timeouts
@gjermundgaraba
Copy link
Copy Markdown
Contributor Author

The failing test is, as far as I can tell, not related to these changes. Seems to be a flakiness problem, so I opened a separate PR for that: #304

Copy link
Copy Markdown
Owner

@devgianlu devgianlu left a comment

Choose a reason for hiding this comment

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

Thank you for the hardening work. I think at some point there should a "reconnatable conn" abstraction to be reused between the AP and the Dealer since they share a bunch of logic.

@devgianlu devgianlu merged commit 516afb9 into devgianlu:master Apr 12, 2026
9 of 10 checks passed
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.

2 participants