Skip to content

Commit

Permalink
Merge pull request #67 from matrix-org/kegan/rust-panic
Browse files Browse the repository at this point in the history
bugfix: don't let channels be closed more than once
  • Loading branch information
kegsay authored May 23, 2024
2 parents d8bd962 + 44dbbf4 commit a6c91dd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/api/rust/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ func (c *RustClient) SendMessage(t ct.TestLike, roomID, text string) (eventID st

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

0 comments on commit a6c91dd

Please sign in to comment.