From 283e04b54c3dace0593a226befc4d21f40641d3a Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Tue, 25 Mar 2025 16:25:24 +0000 Subject: [PATCH 1/2] Rejig how we initialise the timeline This accounts for the fact that the timeline callback can now be called before `AddListener` returns. --- internal/api/rust/rust.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/api/rust/rust.go b/internal/api/rust/rust.go index 830b789..63c4be0 100644 --- a/internal/api/rust/rust.go +++ b/internal/api/rust/rust.go @@ -10,8 +10,8 @@ import ( "time" "github.com/matrix-org/complement-crypto/internal/api" - "github.com/matrix-org/complement-crypto/internal/api/rust/matrix_sdk_ffi" "github.com/matrix-org/complement-crypto/internal/api/rust/matrix_sdk_base" + "github.com/matrix-org/complement-crypto/internal/api/rust/matrix_sdk_ffi" "github.com/matrix-org/complement/ct" "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/must" @@ -717,8 +717,9 @@ func (c *RustClient) ensureListening(t ct.TestLike, roomID string) { // _before_ we have set the initial entries in the timeline. This would cause a lost update // as setting the initial entries clears the timeline, which can then result in test flakes. waiter := helpers.NewWaiter() + c.rooms[roomID].timeline = make([]*api.Event, 0) result := mustGetTimeline(t, r).AddListener(&timelineListener{fn: func(diff []*matrix_sdk_ffi.TimelineDiff) { - waiter.Waitf(t, 5*time.Second, "timed out waiting for Timeline.AddListener to return") + defer waiter.Finish() timeline := c.rooms[roomID].timeline var newEvents []*api.Event c.Logf(t, "[%s]AddTimelineListener[%s] TimelineDiff len=%d", c.userID, roomID, len(diff)) @@ -821,9 +822,9 @@ func (c *RustClient) ensureListening(t ct.TestLike, roomID string) { } }}) c.rooms[roomID].stream = result - c.rooms[roomID].timeline = make([]*api.Event, 0) c.Logf(t, "[%s]AddTimelineListener[%s] set up", c.userID, roomID) - waiter.Finish() + waiter.Waitf(t, 5*time.Second, "timed out waiting for Timeline.AddListener to return") + } type timelineWaiter struct { From 1a08916b428987aa7ce32b318cb2926291e1d8eb Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Tue, 25 Mar 2025 16:47:58 +0000 Subject: [PATCH 2/2] Invoke the rooms listener async as per comment --- internal/api/rust/rust.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/api/rust/rust.go b/internal/api/rust/rust.go index 63c4be0..de62303 100644 --- a/internal/api/rust/rust.go +++ b/internal/api/rust/rust.go @@ -697,7 +697,12 @@ func (c *RustClient) ensureListening(t ct.TestLike, roomID string) { return false } if room := c.findRoom(t, roomID); room != nil { - c.ensureListening(t, roomID) // this should work now + // Do this asynchronously because adding a timeline listener is done synchronously + // which will cause "signal arrived during cgo execution" if it happens within + // this rooms listener callback. + go func() { + c.ensureListening(t, roomID) // this should work now + }() return true } return false