From 44dbbf49279fbe8dabc201d415fa2c683fab1104 Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Wed, 22 May 2024 12:16:09 +0100 Subject: [PATCH] bugfix: don't let channels be closed more than once --- internal/api/rust/rust.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/api/rust/rust.go b/internal/api/rust/rust.go index d707822..e9d9855 100644 --- a/internal/api/rust/rust.go +++ b/internal/api/rust/rust.go @@ -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 @@ -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) + } } } }