fix: Don't fail entire preview requests when auxiliary requests fail #2448
Open
nex
wants to merge 9 commits from
nex/fix/nonatomic-url-previews into main
pull from: nex/fix/nonatomic-url-previews
merge into: continuwuation:main
continuwuation:main
continuwuation:renovate/serde-saphyr-2.x
continuwuation:renovate/rspress-plugin-client-redirects-2.x-lockfile
continuwuation:renovate/rspress-core-2.x-lockfile
continuwuation:aranje/illegal-car-mods
continuwuation:nex/refactor/ruma-state-res
continuwuation:ginger/client-credentials
continuwuation:renovate/crate-ci-committed-1.x
continuwuation:ginger/msc4322-2media2redaction
continuwuation:renovate/lock-file-maintenance
continuwuation:renovate/parking_lot-0.x
continuwuation:renovate/p256-0.x
continuwuation:renovate/rust-zerover-patch-updates
continuwuation:renovate/pin-dependencies
continuwuation:ginger/msc4388
continuwuation:nex/feat/reorganise-commands
continuwuation:renovate/cargo-bins-cargo-binstall-1.x
continuwuation:nex/feat/lockfree-event-builder
continuwuation:nex/fix/local-event-current-state
continuwuation:nex/feat/notary-server
continuwuation:nex/feat/admin-api
continuwuation:jade/mass-rename
continuwuation:nex/feat/msc-fed-bidi-ping
continuwuation:nex/feat/centralise-remote-memberships
continuwuation:morgan/arm64-runner
continuwuation:renovate/argon2-0.x
continuwuation:next/meta/disable-ci-build-cache
continuwuation:fix/26.7.3
continuwuation:1235-add-arm-deb
continuwuation:nex/meta/release-schedule
continuwuation:nex/feat/pdu-versions
continuwuation:ginger/revert-direct-tls
continuwuation:nex/fix/federated-invite-revoke
continuwuation:nex/fix/plunger
continuwuation:jade/perf/gme-rebased
continuwuation:nex/perf/get-missing-events2
continuwuation:nex/backport/v0.5.11
continuwuation:nex/backport/v0.5.10-backport
continuwuation:nex/feat/msc4491-invite-reasons-in-room-creation
continuwuation:nex/feat/deprecated-room-versions
continuwuation:release/v0.5.9
continuwuation:nex/feat/enable-debug-log-release-builds
continuwuation:nex/feat/room-purging
continuwuation:nex/feat/room-shutdown
continuwuation:ginger/ruma-upstreaming
continuwuation:jade/tls-backends
continuwuation:ginger/email-fixes
continuwuation:jade/changelog-labels
continuwuation:nex/fix/v12-publishing
continuwuation:jade/build-info
continuwuation:jade/purge-sync-tokens
continuwuation:ginger/terms-and-conditions
continuwuation:ginger/remove-sliding-sync-proxy
continuwuation:nex/fix/pusher-association
continuwuation:ginger/email-support
continuwuation:jade/community-guidelines
continuwuation:nex/fix/federation-format
continuwuation:jade/git-deps-updates
continuwuation:jade/changelog-check
continuwuation:jade/rust-1-92
continuwuation:ginger/password-reset
continuwuation:nex/experiment/push-gateway-logs
continuwuation:ginger/msc3575-obliteration
continuwuation:nex/feat/block-busted-rooms
continuwuation:nex/fix/informative-startup-errs
continuwuation:ginger/no-left-room-initial-sync
continuwuation:jade/docker-entrypoint
continuwuation:jade/dehydrated-devices
continuwuation:ginger/complement-fixes
continuwuation:nex/fix/stale-destination-cache
continuwuation:nex/experiment/sync-mutex
continuwuation:tcpipuk/docker-docs
continuwuation:jade/snafu
continuwuation:jade/rand-update
continuwuation:nex/stateres-refactor
continuwuation:ginger/779-in-troubleshooting
continuwuation:jade/liveit-guide
continuwuation:jade/http3
continuwuation:nex/feat/admin-hide-empty-rooms
continuwuation:ginger/oobe
continuwuation:nex/fix/debian-thingy
continuwuation:jade/ldap-admin-check
continuwuation:nex/fix/remote-restricted-joins
continuwuation:nex/feat/msc4406-sender-ignored
continuwuation:jade/deadlock-detection
continuwuation:jade/get-started
continuwuation:jade/docs-guide
continuwuation:ginger/fix-local-invites
continuwuation:nex/fix/tpi
continuwuation:nex/feat/room-deletion
continuwuation:nex/feat/msc4322-media-redaction
continuwuation:ginger/stitched-order
continuwuation:ginger/deps/update-rspress
continuwuation:jade/admin-announce-improvements
continuwuation:ginger/xtask-improvements
continuwuation:jade/improve-admin-config-display
continuwuation:nex/fix/better-stateres-error-logs
continuwuation:jade/sender-timeouts
continuwuation:nex/feat/custom-v12-room-ids
continuwuation:ginger/update-metadata
continuwuation:nex/feat/admin-force-logout
continuwuation:tom/max-perf-docs
continuwuation:nex/fix/invalid-appservice-reg
continuwuation:nex/feat/antispam
continuwuation:nex/feat/account-locking
continuwuation:jade/logging-cleanup
continuwuation:jade/remove-legacy-appservice-auth
continuwuation:nex/fix/key-query
continuwuation:jade/update-prek
continuwuation:nex/fix/room-summaries
continuwuation:ginger/restrict-admin-commands
continuwuation:ginger/enable-console-by-default
continuwuation:jade/tag-fixes
continuwuation:jade/otlp
continuwuation:nex/meta/pull-req-template
continuwuation:nex/fix/fed-invite-compliance
continuwuation:nex/feat/build-commit
continuwuation:nex/feat/join-logging
continuwuation:jade/mailmap-updates
continuwuation:jade/hack-ci-tmp
continuwuation:jade/v12-stable
continuwuation:jade/relations
continuwuation:ginger/database-refactor
continuwuation:jade/fix-ldap-uiaa
continuwuation:nex/fix/validation
continuwuation:ginger/nuke-invalid-msc4133-fields-in-migration
continuwuation:ginger/downgrade-artifact-actions
continuwuation:oddlid/reload-fix
continuwuation:jade/fix-assert
continuwuation:ginger/sync-v3-cleanup
continuwuation:ginger/remove-absolute-action-urls
continuwuation:jade/website
continuwuation:nex/fix/backoff
continuwuation:ginger/fix-mdbook-for-0.5
continuwuation:ginger/no-docker-on-prs
continuwuation:backport/v0.5.0-rc.8-1
continuwuation:nex/fed-improvements
continuwuation:jade/rust-1.90
continuwuation:jade/mirror-dockerhub
continuwuation:jade/clippy-fixes
continuwuation:jade/fix-support
continuwuation:jade/clean-images
continuwuation:jade/wal-compression-type
continuwuation:jade/flake-clone
continuwuation:ginger/upload-rpms-on-schedule
continuwuation:nex/fix/incoming-fetch
continuwuation:nex/fix/upgrade
continuwuation:tom/ci-fedora-rpm
continuwuation:jade/ci-release-fix
continuwuation:jade/rocksdb-10-5
continuwuation:ginger/fix-msc4133-migration
continuwuation:ginger/migrate-busted-tz
continuwuation:hydra/public
continuwuation:nex/feat/manual-extremities
continuwuation:nex/feat/async-media
continuwuation:nex/feat/fast-joins-hack-do-not-use-DO-NOT-USE
continuwuation:nex/feat/better-logging
continuwuation:trigger-ci-so-latest-isnt-on-illegal-car-mods
continuwuation:nex/feat/pins-backfill
continuwuation:jade/tuwunel-2025-06-old
continuwuation:jade/ai-slop-db-docs
continuwuation:nex/fix-create-auth
continuwuation:jade/version-stats
continuwuation:jade/read-receipts
continuwuation:jade/rust-toolchain-no-targets
continuwuation:jade/logging-features
continuwuation:jade/syncv5-typing
continuwuation:jade/msc2815
continuwuation:morguldir/see-eye
continuwuation:jade/css-small-screen
continuwuation:nex/wip-751
continuwuation:tuwunel-rebase
continuwuation:test
continuwuation:oddlid/rename-admin-room-bot
continuwuation:strawberry/nix-ci-stuff
continuwuation:strawberry/valgrind
continuwuation:phonemain
continuwuation:strawberry/morgs-snake-sync-jason-main
continuwuation:newer-media-endpoints
continuwuation:folly-coroutines-async-io
continuwuation:federation-retry-timer-port
continuwuation:bad-attempt-at-extracting-homeserver-signing-key
continuwuation:room-deletion-attempt-do-not-use
No reviewers
Labels
Clear labels
Abandoned
This pull request appears to be abandoned by its author.
Blocked
This pull request or issue is currently blocked from being merged/closed
Bug
Something isn't working as intended
Changelog
Added
Changelog entry added
Changelog
Missing
No changelog when one is needed
Changelog
None
Changelog is unnecesary for this change
Cherry-picking
Commits picked from other conduit projects
Database
This requires or includes changes to the database
Dependencies
Something dependency related
Dependencies/Renovate
Automatic dependency upgrades by Renovate
Difficulty
Easy
Low difficulty to implement - touches few parts of the codebase, low complexity
Difficulty
Hard
High difficulty to implement - touches many parts of the codebase, high complexity
Difficulty
Medium
Medium difficulty to implement - touches more parts of the codebase, higher complexity
Documentation
Improvements or additions to documentation
Enhancement
New feature or request
Good first issue
Good for newcomers
Help wanted
Additional eyes and keyboards are required for this one
Inherited
Issues that have been inhereted from the project pre-fork
Matrix/Administration
Features pertaining to homeserver administration
Matrix/Appservices
Features pertaining to the appservice API
Matrix/Auth
Features pertaining to authentication
Matrix/Client
Features pertaining to client-to-server interactions
Matrix/Core
Issues relating to core matrix functionality, such as state resolution and PDU formats
Matrix/E2EE
Issues related to end to end encryption
Matrix/Federation
Features pertaining to server-to-server interactions
Matrix/Hydra
Issues related to room version 12 and related changes (temporary label)
Matrix/MSC
Features pertaining to unstable matrix features
Matrix/Media
Features pertaining to media interactions
Matrix/T&S
Changes or issues related to trust & safety tooling
Merge
This PR is ready to be merged
Merge/Manual
This PR should be manually merged
Merge/Squash
This PR should be squashed when it is merged
Meta
Related to housekeeping, maintenance, or other repo-meta.
Meta/CI
Issues related to CI changes
Meta/Packaging
Packaging
Priority
Blocking
This issue is blocking the next release
Priority
High
This issue is very important
Priority
Low
This issue is of a rather low priority
Security
This item is related to general security
Status
Confirmed
This issue has enough information and is confirmed
Status
Duplicate
This issue or pull request already exists
Status
Invalid
This issue doesn't seem right
Status
Needs Investigation
This issue needs further investigation
Support
Questions or support requests
bob the builder
pdu logic rewrite starring nexus nicholson
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
Assignees
Clear assignees
No assignees
6 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
continuwuation/continuwuity!2448
Loading…
Reference in a new issue
No description provided.
Delete branch "nex/fix/nonatomic-url-previews"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
#2437 was really annoying me so I fixed it, and also added additional opengraph tags to improve spec compliance (although this isn't a replacement for arbitrary OG tags, I'll do that in another PR since I unfortunately saw how awful our url preview storage is)
Fixes #2437
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
i am planning on completely revamping this in the media rewrite (since the two codebases are very linked together), feel free to change it early but i might replace it a second time when i finish the rewrite
That's fine, my plan was to write a migration that
I wouldn't be too distraught to see it improved further by a rewrite later
@ -349,0 +351,4 @@..Default::default() /* TODO(nex): This weird manual field de/serialisation just* needs replacing with JSON storage to avoid this mess.* This is consequently intentionally dropping information* added later (like image alt text). I'll do it later. */This will be rewritten as part of the media rewrite, feel free to change this todo (and the one on L251) over to me
I'll cc you into the TODO but I'll leave it assigned to me also so that I don't forget to do my aforementioned interim migration
sounds great
@nex wrote in #2448 (comment):
whatever lets me delete all that data has my APPROVED
@nex wrote in #2448 (comment):
My current "plan" (if you can call if that) is to just use serde's standard serializer on the structs, and probably actually using the value instead of storing everything in the key (i believe previews used that same (stupid) method of serialization and storage).
(i might be misremembering, i have it written down somewhere but my memory is ass)
missing changelog :^)
@ -301,0 +336,4 @@preview_data.image_height = image_data.image_height;preview_data.image_type = obj.properties.get("image:type")no need for image: you can just use type https://docs.rs/webpage/2.1.0/src/webpage/opengraph.rs.html#55-88
@ -301,0 +344,4 @@.flatten();preview_data.image_alt = obj.properties.get("image:alt")same here
@ -307,0 +360,4 @@preview_data.video_size = video_data.video_size;preview_data.video_type = obj.properties.get("video:type")same here
@ -307,0 +368,4 @@.flatten();preview_data.video_alt = obj.properties.get("video:alt")same here
@ -307,0 +355,4 @@|e| info!(error=?e, asset_url=%obj.url, "Could not download URL preview video"),) {preview_data.video = video_data.video;preview_data.video_width = video_data.video_width;not set by download_video so .get("width")
@ -219,6 +219,7 @@ pub(crate) async fn get_media_preview_route()));}info!("Fetching a URL preview for {url} on behalf of {sender_user}");debug! ?
I don't think so, I'd like to know when my server is doing things on behalf of users, like making external requests (especially useful in untrusted environments like continuwuity.rocks). Continuwuity has a bad habit of under-logging so I'd like to avoid debug! et al unless the log is actually useful to debugging, not just normal operation
Requests should be logged at the router level, and this log should be a structured log anyway.
My server receives an average of 10 requests per second with spikes into the thousands in some situations, and that's normal for a federated server. Expecting people to use the router logs for this stuff is infeasible
@ -307,0 +356,4 @@) {preview_data.video = video_data.video;preview_data.video_width = video_data.video_width;preview_data.video_height = video_data.video_height;not set by download_video so .get("height")
@ -319,0 +390,4 @@preview_data.determiner = props.get("determiner").cloned();preview_data.locale = props.get("locale").cloned();preview_data.site_name = props.get("site_name").cloned();preview_data.site_type = props.get("type").cloned();i think it should be og_type here as it's an extended type
@ -319,0 +391,4 @@preview_data.locale = props.get("locale").cloned();preview_data.site_name = props.get("site_name").cloned();preview_data.site_type = props.get("type").cloned();preview_data.url = props.get("url").cloned().or_else(|| Some(url.to_owned()));this will always be None, webpage puts og:type into og_type and not into properties
@ -84,3 +84,3 @@.timeout(Duration::from_secs(config.url_preview_timeout)).redirect(redirect::Policy::limited(3)).user_agent(url_preview_user_agent).user_agent(url_preview_user_agent.replace("<version>", conduwuit::version_ua()))ew.
I did this because the docstring for that option starts with
continuwuity/<version>and I naively assumed that<version>would be substituted with the real version if I specified a custom UA, and then was taken by surprised whencontinuwuity/<version>literally appeared in my logs. Anything more than a replace will also then require a documentation update, which is wayy out of scope for this fix with some cheap wins@ -24,1 +25,4 @@pub struct UrlPreviewData {// From https://ogp.me//// The title of your object as it should appear within the graph/// "The Rock".why is dwayne johnson in my doc comment
I copied the descriptions from the ogp website until I got bored
works great!
I'd replace the
info!with a structured log like jade suggested, other than that it lgtme785d78b8879c5af78cdmost recent push fails rust format, but otherwise is ready to go and works extremely well.
TODO
@ -10,2 +10,3 @@use conduwuit::{Err, Result, debug, err, utils::response::LimitReadExt};use conduwuit::{Err, Result, debug, err, utils::response::LimitReadExt, info};use ipaddress::IPAddress;use lettre::message::header::ContentType;we already depend on mime, use it directly
I am too tired to be giving proper code review, but:
url_previewfeature disabled (or do we just want to remove that compile option?)@ -219,10 +219,15 @@ pub(crate) async fn get_media_preview_route()));}info!("Fetching a URL preview for {url} on behalf of {sender_user}");(1) please use structured logging, (2) I think this is unlikely to be relevant to typical server admins, and is just going to be log spam
@ -115,3 +154,1 @@| audio if audio.starts_with("audio/") =>self.download_audio(url.as_str(), None).await?,| _ => return Err!(Request(Unknown("Unsupported Content-Type"))),| img if img.starts_with("image/") => self.download_image(url.as_str()).await?,can we also
url.join(&obj.url)to deal with relative paths?@ -300,3 +345,1 @@preview_data = self.download_video(&obj.url, Some(preview_data)).await?;preview_data.video_width = obj.properties.get("width").and_then(|v| v.parse().ok());preview_data.video_height = obj.properties.get("height").and_then(|v| v.parse().ok());info!(asset_url=%obj.url, "Downloading preview video");this is gonna log even when downloading audio/videos is disabled (same for in the audio function)
@ -315,0 +381,4 @@preview_data.video_type = None;preview_data.video_alt = None;preview_data.video_height = None;preview_data.video_width = None;video_size (and image_size above?)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.