client,bridgev2/matrix: fix context used for async uploads
Some checks are pending
Go / Lint (latest) (push) Waiting to run
Go / Build (old, libolm) (push) Waiting to run
Go / Build (latest, libolm) (push) Waiting to run
Go / Build (old, goolm) (push) Waiting to run
Go / Build (latest, goolm) (push) Waiting to run

This commit is contained in:
Tulir Asokan 2026-01-20 12:06:55 +02:00
commit a55693bbd7
2 changed files with 10 additions and 2 deletions

View file

@ -403,6 +403,7 @@ func (as *ASIntent) UploadMediaStream(
removeAndClose(replFile)
removeAndClose(tempFile)
}
req.AsyncContext = zerolog.Ctx(ctx).WithContext(as.Connector.Bridge.BackgroundCtx)
startedAsyncUpload = true
var resp *mautrix.RespCreateMXC
resp, err = as.Matrix.UploadAsync(ctx, req)
@ -435,6 +436,7 @@ func (as *ASIntent) doUploadReq(ctx context.Context, file *event.EncryptedFileIn
as.Connector.uploadSema.Release(int64(len(req.ContentBytes)))
}
}
req.AsyncContext = zerolog.Ctx(ctx).WithContext(as.Connector.Bridge.BackgroundCtx)
var resp *mautrix.RespCreateMXC
resp, err = as.Matrix.UploadAsync(ctx, req)
if resp != nil {

View file

@ -1933,10 +1933,15 @@ func (cli *Client) UploadAsync(ctx context.Context, req ReqUploadMedia) (*RespCr
}
req.MXC = resp.ContentURI
req.UnstableUploadURL = resp.UnstableUploadURL
if req.AsyncContext == nil {
req.AsyncContext = cli.cliOrContextLog(ctx).WithContext(context.Background())
}
go func() {
_, err = cli.UploadMedia(ctx, req)
_, err = cli.UploadMedia(req.AsyncContext, req)
if err != nil {
cli.Log.Error().Stringer("mxc", req.MXC).Err(err).Msg("Async upload of media failed")
zerolog.Ctx(req.AsyncContext).Err(err).
Stringer("mxc", req.MXC).
Msg("Async upload of media failed")
}
}()
return resp, nil
@ -1972,6 +1977,7 @@ type ReqUploadMedia struct {
ContentType string
FileName string
AsyncContext context.Context
DoneCallback func()
// MXC specifies an existing MXC URI which doesn't have content yet to upload into.