Skip to content

Commit

Permalink
Add 'FIXME's for deadman timer reset race
Browse files Browse the repository at this point in the history
  • Loading branch information
iaburton committed Apr 24, 2023
1 parent 8c8b886 commit 5babfb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion socketmode/deadman.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func (smc *deadmanTimer) Elapsed() <-chan time.Time {
}

func (smc *deadmanTimer) Reset() {
// Note that this is the correct way to Reset a non-expired timer
// FIXME: Race on "deadmanTimer", timer channel cannot be read concurrently while resetting.
// "This should not be done concurrent to other receives from the Timer's channel."
// https://pkg.go.dev/time#Timer.Reset
// See socket_mode_managed_conn.go lines ~59 & ~151.
if !smc.timer.Stop() {
select {
case <-smc.timer.C:
Expand Down
11 changes: 10 additions & 1 deletion socketmode/socket_mode_managed_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ func (smc *Client) RunContext(ctx context.Context) error {

func (smc *Client) run(ctx context.Context, connectionCount int) error {
messages := make(chan json.RawMessage, 1)
deadmanTimer := newDeadmanTimer(smc.maxPingInterval)

// FIXME: Race on "deadmanTimer", timer channel cannot be read concurrently while resetting.
// "This should not be done concurrent to other receives from the Timer's channel."
// https://pkg.go.dev/time#Timer.Reset
// See deadman.go line ~22.
deadmanTimer := newDeadmanTimer(smc.maxPingInterval)
pingHandler := func(_ string) error {
deadmanTimer.Reset()

Expand Down Expand Up @@ -143,6 +147,11 @@ func (smc *Client) run(ctx context.Context, connectionCount int) error {
if err := conn.Close(); err != nil {
smc.Debugf("Failed to close connection: %v", err)
}

// FIXME: Race on "deadmanTimer", timer channel cannot be read concurrently while resetting.
// "This should not be done concurrent to other receives from the Timer's channel."
// https://pkg.go.dev/time#Timer.Reset
// See deadman.go line ~22.
case <-deadmanTimer.Elapsed():
sendErr(errors.New("ping timeout: Slack did not send us WebSocket PING for more than Client.maxInterval"))

Expand Down

0 comments on commit 5babfb7

Please sign in to comment.