Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Media Key Error When 2 Clients Request Federated Media Simultaneously #615

Open
PseudoResonance opened this issue Sep 1, 2024 · 1 comment
Labels

Comments

@PseudoResonance
Copy link

With 2 clients open to the same chat at the same time, I got what appears to be an error related to the media lock, and 2 requests trying to save the received image simultaneously. One client showed the image correctly, and the other said "Error downloading image" until I refreshed the chat. There's only a single instance of MMR running as ID 0 at the moment, so it shouldn't have been caused by some issue with synchronization across a cluster.

Logs
time="2024-09-01 09:34:12.311 Z" level=warning msg="Access token cache is disabled for this host" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="allow_redirect=true" remoteAddr="INTERNALIP1:40056" requestId=REQ-573 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.76 Chrome/126.0.6478.185 Electron/31.3.1 Safari/537.36"
time="2024-09-01 09:34:12.311 Z" level=debug msg="Checking access token with homeserver" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="allow_redirect=true" remoteAddr="INTERNALIP1:40056" requestId=REQ-573 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.76 Chrome/126.0.6478.185 Electron/31.3.1 Safari/537.36"
time="2024-09-01 09:34:12.311 Z" level=debug msg="Calling GET https://matrix.HOMESERVER/_matrix/client/v3/account/whoami" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="allow_redirect=true" remoteAddr="INTERNALIP1:40056" requestId=REQ-573 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.76 Chrome/126.0.6478.185 Electron/31.3.1 Safari/537.36"
time="2024-09-01 09:34:12.352 Z" level=debug msg="Getting server API URL for matrix.org"
time="2024-09-01 09:34:12.352 Z" level=debug msg="Testing if matrix.org is an IP address"
time="2024-09-01 09:34:12.352 Z" level=debug msg="Testing if a default port was used. Using default = true"
time="2024-09-01 09:34:12.352 Z" level=debug msg="Doing .well-known lookup on matrix.org"
time="2024-09-01 09:34:12.437 Z" level=warning msg="Access token cache is disabled for this host" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="" remoteAddr="INTERNALIP2:59316" requestId=REQ-574 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:12.437 Z" level=debug msg="Checking access token with homeserver" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="" remoteAddr="INTERNALIP2:59316" requestId=REQ-574 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:12.437 Z" level=debug msg="Calling GET https://matrix.HOMESERVER/_matrix/client/v3/account/whoami" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="" remoteAddr="INTERNALIP2:59316" requestId=REQ-574 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:12.454 Z" level=debug msg="Getting server API URL for matrix.org"
time="2024-09-01 09:34:12.454 Z" level=debug msg="Testing if matrix.org is an IP address"
time="2024-09-01 09:34:12.454 Z" level=debug msg="Testing if a default port was used. Using default = true"
time="2024-09-01 09:34:12.454 Z" level=debug msg="Doing .well-known lookup on matrix.org"
time="2024-09-01 09:34:12.510 Z" level=debug msg="Checking if WK host is an IP: matrix-federation.matrix.org"
time="2024-09-01 09:34:12.511 Z" level=debug msg="Checking if WK is using default port? false"
time="2024-09-01 09:34:12.511 Z" level=debug msg="Server API URL for matrix.org is https://matrix-federation.matrix.org:443 (WK; explicit port)"
time="2024-09-01 09:34:12.511 Z" level=warning msg="No signing key is configured for this domain! See `signingKeyPath` in the sample config for details." allowRedirect=true allowRemote=true authServerName="" authUserId="@USER:HOMESERVER" contentLength=0 contentType="" filename="" host=HOMESERVER mediaId=MEDIA_ID method=GET queryString="allow_redirect=true" remoteAddr="INTERNALIP1:40056" requestId=REQ-573 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID server=matrix.org userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.76 Chrome/126.0.6478.185 Electron/31.3.1 Safari/537.36"
time="2024-09-01 09:34:12.511 Z" level=debug msg="Doing federated GET to https://matrix-federation.matrix.org:443/_matrix/media/v3/download/matrix.org/MEDIA_ID?allow_remote=false&allow_redirect=true with host matrix-federation.matrix.org:443" allowRedirect=true allowRemote=true authServerName="" authUserId="@USER:HOMESERVER" contentLength=0 contentType="" filename="" host=HOMESERVER mediaId=MEDIA_ID method=GET queryString="allow_redirect=true" remoteAddr="INTERNALIP1:40056" requestId=REQ-573 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID server=matrix.org userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.76 Chrome/126.0.6478.185 Electron/31.3.1 Safari/537.36"
time="2024-09-01 09:34:12.511 Z" level=debug msg="Checking if WK host is an IP: matrix-federation.matrix.org"
time="2024-09-01 09:34:12.511 Z" level=debug msg="Checking if WK is using default port? false"
time="2024-09-01 09:34:12.511 Z" level=debug msg="Server API URL for matrix.org is https://matrix-federation.matrix.org:443 (WK; explicit port)"
time="2024-09-01 09:34:12.512 Z" level=warning msg="No signing key is configured for this domain! See `signingKeyPath` in the sample config for details." allowRedirect=false allowRemote=true authServerName="" authUserId="@USER:HOMESERVER" contentLength=0 contentType="" filename="" host=HOMESERVER mediaId=MEDIA_ID method=GET queryString="" remoteAddr="INTERNALIP2:59316" requestId=REQ-574 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID server=matrix.org userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:12.512 Z" level=debug msg="Doing federated GET to https://matrix-federation.matrix.org:443/_matrix/media/v3/download/matrix.org/MEDIA_ID?allow_remote=false&allow_redirect=true with host matrix-federation.matrix.org:443" allowRedirect=false allowRemote=true authServerName="" authUserId="@USER:HOMESERVER" contentLength=0 contentType="" filename="" host=HOMESERVER mediaId=MEDIA_ID method=GET queryString="" remoteAddr="INTERNALIP2:59316" requestId=REQ-574 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID server=matrix.org userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:12.924 Z" level=warning msg="Access token cache is disabled for this host" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="" remoteAddr="INTERNALIP3:49678" requestId=REQ-575 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:12.924 Z" level=debug msg="Checking access token with homeserver" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="" remoteAddr="INTERNALIP3:49678" requestId=REQ-575 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:12.924 Z" level=debug msg="Calling GET https://matrix.HOMESERVER/_matrix/client/v3/account/whoami" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="" remoteAddr="INTERNALIP3:49678" requestId=REQ-575 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:14.851 Z" level=debug msg="Lock acquired until 2024-09-01 09:39:11.843254928 +0000 UTC" allowRedirect=false allowRemote=true authServerName="" authUserId="@USER:HOMESERVER" contentLength=0 contentType="" filename="" host=HOMESERVER mediaId=MEDIA_ID method=GET queryString="" remoteAddr="INTERNALIP2:59316" requestId=REQ-574 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID server=matrix.org userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:16.976 Z" level=debug msg="Unlocking upload lock" allowRedirect=false allowRemote=true authServerName="" authUserId="@USER:HOMESERVER" contentLength=0 contentType="" filename="" host=HOMESERVER mediaId=MEDIA_ID method=GET queryString="" remoteAddr="INTERNALIP2:59316" requestId=REQ-574 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID server=matrix.org userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:16.993 Z" level=debug msg="Lock acquired until 2024-09-01 09:39:13.992139095 +0000 UTC" allowRedirect=true allowRemote=true authServerName="" authUserId="@USER:HOMESERVER" contentLength=0 contentType="" filename="" host=HOMESERVER mediaId=MEDIA_ID method=GET queryString="allow_redirect=true" remoteAddr="INTERNALIP1:40056" requestId=REQ-573 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID server=matrix.org userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.76 Chrome/126.0.6478.185 Electron/31.3.1 Safari/537.36"
time="2024-09-01 09:34:17.003 Z" level=info msg="Replying with result: *_responses.DownloadResponse &{ContentType:application/octet-stream Filename:download SizeBytes:936 Data:0xc0007813b0 TargetDisposition:infer}" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="" remoteAddr="INTERNALIP3:49678" requestId=REQ-575 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:17.005 Z" level=info msg="Replying with result: *_responses.DownloadResponse &{ContentType:application/octet-stream Filename:download SizeBytes:936 Data:0xc000631998 TargetDisposition:infer}" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="" remoteAddr="INTERNALIP2:59316" requestId=REQ-574 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Element X/0.5.0 (samsung SM-S908U; Android 14; UP1A.231005.007.S908USQS6EXG8; Sdk d65e33ca6)"
time="2024-09-01 09:34:17.244 Z" level=debug msg="Unlocking upload lock" allowRedirect=true allowRemote=true authServerName="" authUserId="@USER:HOMESERVER" contentLength=0 contentType="" filename="" host=HOMESERVER mediaId=MEDIA_ID method=GET queryString="allow_redirect=true" remoteAddr="INTERNALIP1:40056" requestId=REQ-573 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID server=matrix.org userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.76 Chrome/126.0.6478.185 Electron/31.3.1 Safari/537.36"
time="2024-09-01 09:34:17.246 Z" level=error msg="Unexpected error locating media: pq: duplicate key value violates unique constraint \"media_index\"" allowRedirect=true allowRemote=true authServerName="" authUserId="@USER:HOMESERVER" contentLength=0 contentType="" filename="" host=HOMESERVER mediaId=MEDIA_ID method=GET queryString="allow_redirect=true" remoteAddr="INTERNALIP1:40056" requestId=REQ-573 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID server=matrix.org userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.76 Chrome/126.0.6478.185 Electron/31.3.1 Safari/537.36"
time="2024-09-01 09:34:17.246 Z" level=info msg="Replying with result: *_responses.ErrorResponse &{Code:M_UNKNOWN Message:Unexpected Error InternalCode:M_UNKNOWN}" contentLength=0 contentType="" host=HOMESERVER method=GET queryString="allow_redirect=true" remoteAddr="INTERNALIP1:40056" requestId=REQ-573 resource=/_matrix/client/v1/media/download/matrix.org/MEDIA_ID userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.76 Chrome/126.0.6478.185 Electron/31.3.1 Safari/537.36"
@PseudoResonance
Copy link
Author

Additionally, I believe I saw this affect things like URL previews. I don't have the logs unfortunately, but on very rare occasions I've had URL previews where the image won't load and the server had the same error about duplicate keys because 2 users requested the preview simultaneously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants