Revert "Revert "client: unblock connect without network""

This reverts commit ea4626107c.

Adds waiting support for initial connection established to avoid locking
up gotd. This isn't extremely pretty but should do the job for now.
This commit is contained in:
Toni Spets
2025-05-27 07:40:20 +03:00
parent ea4626107c
commit 0f36833e89
3 changed files with 65 additions and 38 deletions
+13
View File
@@ -218,6 +218,19 @@ func parseRandomID(txnID networkid.RawTransactionID) int64 {
}
func (t *TelegramClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.MatrixMessage) (resp *bridgev2.MatrixMessageResponse, err error) {
// Handle Matrix events only after initial connection has been established to avoid deadlocking gotd
select {
case <-t.initialized:
default:
zerolog.Ctx(ctx).Warn().Msg("Got Matrix event before connected, blocking until done")
select {
case <-t.initialized:
case <-ctx.Done():
return nil, ctx.Err()
}
}
peer, err := t.inputPeerForPortalID(ctx, msg.Portal.ID)
if err != nil {
return nil, err