Skip to content

Commit a6c91dd

Browse files
authored
Merge pull request #67 from matrix-org/kegan/rust-panic
bugfix: don't let channels be closed more than once
2 parents d8bd962 + 44dbbf4 commit a6c91dd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/api/rust/rust.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ func (c *RustClient) SendMessage(t ct.TestLike, roomID, text string) (eventID st
440440

441441
func (c *RustClient) TrySendMessage(t ct.TestLike, roomID, text string) (eventID string, err error) {
442442
t.Helper()
443+
var isChannelClosed atomic.Bool
443444
ch := make(chan bool)
444445
// we need a timeline listener before we can send messages, AND that listener must be attached to the
445446
// same *Room you call .Send on :S
@@ -463,7 +464,9 @@ func (c *RustClient) TrySendMessage(t ct.TestLike, roomID, text string) (eventID
463464
// else this will panic on the 2nd call.
464465
if eventID == "" {
465466
eventID = ev.ID
466-
close(ch)
467+
if isChannelClosed.CompareAndSwap(false, true) {
468+
close(ch)
469+
}
467470
}
468471
}
469472
}

0 commit comments

Comments
 (0)