[NOWEB] - fetch media raises timeout if media is not available on servers
When retrieving historical messages using the downloadMedia=true parameter, I encounter a 504 Gateway Timeout error, especially for media files created before scanning the QR code (i.e., before connecting to the media server).
-
If media exists on the media server: The call succeeds without any problems.
-
If
downloadMedia=false: The call succeeds and the messages are retrieved normally. -
Only happens if the media file does not exist (or is no longer accessible) on the media server.
This behavior causes the entire call to fail, returning a 504 error instead of gracefully handling the missing media.
Version
{
"version": "2025.2.8",
"engine": "NOWEB",
"tier": "PLUS",
"browser": "/usr/bin/chromium"
}
Steps to replicate
- Call the endpoint:
Get https://exampal.com/api/wab1/chats/{chatId}/messages?downloadMedia=true&limit=100
- Verify that the chat contains media files that were created before connecting (scanning QR) to the media server.
- Note the '504 Gateway Timeout' error if the media is not found on the media server.
Expected Behavior
The API should gracefully handle cases where the media is not available by returning the message content (including 'caption') without the media file, rather than causing the entire API call to fail.
Docker Logs
waha-1 | {"level":30,"time":1742071369804,"pid":1,"hostname":"9cd1c79f7a0a","reqId":2495,"req":{"id":2495,"method":"GET","url":"/api/wab1/chats/1234567890XX%40c.us/messages?downloadMedia=true&limit=10","query":{"downloadMedia":"true","limit":"10"},"params":{"0":"api/wab1/chats/[email protected]/messages"}},"res":{"statusCode":304},"responseTime":178,"msg":"request completed"} waha-1 | {"level":20,"time":1742071378948,"pid":1,"hostname":"9cd1c79f7a0a","session":"test","name":"NOWEBEngine","recv":{"tag":"notification","attrs":{"from":"[email protected]","type":"picture","id":"1638647035","t":"1742071377"}},"sent":{"id":"1638647035","to":"[email protected]","class":"notification","type":"picture"},"msg":"sent ack"} waha-1 | {"level":20,"time":1742071378949,"pid":1,"hostname":"9cd1c79f7a0a","session":"test","name":"WhatsappSession","jid":"[email protected]","msg":"Profile picture updated"} waha-1 | {"level":20,"time":1742071378950,"pid":1,"hostname":"9cd1c79f7a0a","session":"test","name":"WhatsappSession","events":{"contacts.update":[{"id":"[email protected]","imgUrl":"changed"}]},"msg":"NOWEB events"} waha-1 | {"level":50,"time":1742071379169,"pid":1,"hostname":"9cd1c79f7a0a","name":"Bootstrap","msg":"Unhandled Rejection at:"} waha-1 | {"level":50,"time":1742071379169,"pid":1,"hostname":"9cd1c79f7a0a","name":"Bootstrap","msg":"Error: item-not-found\n at assertNodeErrorFree (/app/node_modules/@adiwajshing/baileys/lib/WABinary/generic-utils.js:56:15)\n at query (/app/node_modules/@adiwajshing/baileys/lib/Socket/socket.js:143:48)\n at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n at async Object.profilePictureUrl (/app/node_modules/@adiwajshing/baileys/lib/Socket/chats.js:434:24)\n at async NowebPersistentStore.onContactUpdate (/app/dist/core/engines/noweb/store/NowebPersistentStore.js:235:23)"} waha-1 | {"level":30,"time":1742071386666,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"MediaManager","msg":"The message BAE5B3B52AAE4F53 has media, downloading it..."} waha-1 | {"level":30,"time":1742071386668,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"MediaManager","msg":"The message F5ED8E81A7C5E9BEBB445EBD02E288C5 has media, downloading it..."} waha-1 | {"level":30,"time":1742071386677,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"MediaManager","msg":"The message 3F03FF277743EE3C19BD has media, downloading it..."} waha-1 | {"level":30,"time":1742071386752,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"BAE5B3B52AAE4F53"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071386755,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"F5ED8E81A7C5E9BEBB445EBD02E288C5"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071386761,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"3F03FF277743EE3C19BD"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071386912,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"MediaManager","msg":"The message 3EB037013E48F6C6919BBE has media, downloading it..."} waha-1 | {"level":30,"time":1742071386926,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"MediaManager","msg":"The message 3EB0195F8ABD7989294FD9 has media, downloading it..."} waha-1 | {"level":30,"time":1742071387017,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB0195F8ABD7989294FD9"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071387018,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB037013E48F6C6919BBE"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388531,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"BAE5B3B52AAE4F53"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388533,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"F5ED8E81A7C5E9BEBB445EBD02E288C5"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388536,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"3F03FF277743EE3C19BD"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388538,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB0195F8ABD7989294FD9"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388540,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB037013E48F6C6919BBE"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388635,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"BAE5B3B52AAE4F53"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388637,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"F5ED8E81A7C5E9BEBB445EBD02E288C5"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388638,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB0195F8ABD7989294FD9"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388640,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"3F03FF277743EE3C19BD"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388641,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB037013E48F6C6919BBE"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388836,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"BAE5B3B52AAE4F53"},"msg":"sending reupload media request..."} waha-1 | (node:1) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 messages.media-update listeners added to [EventEmitter]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit waha-1 | {"level":30,"time":1742071388839,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"3F03FF277743EE3C19BD"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388841,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"F5ED8E81A7C5E9BEBB445EBD02E288C5"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388842,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB0195F8ABD7989294FD9"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388844,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB037013E48F6C6919BBE"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388931,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"BAE5B3B52AAE4F53"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388933,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"F5ED8E81A7C5E9BEBB445EBD02E288C5"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388937,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":false,"id":"3F03FF277743EE3C19BD"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388939,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB0195F8ABD7989294FD9"},"msg":"sending reupload media request..."} waha-1 | {"level":30,"time":1742071388940,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NOWEBEngineMediaProcessor","key":{"remoteJid":"[email protected]","fromMe":true,"id":"3EB037013E48F6C6919BBE"},"msg":"sending reupload media request..."} waha-1 | {"level":40,"time":1742071391589,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NowebPersistentStore","msg":"got receipt update for non-existent message. key: '{"remoteJid":"[email protected]","id":"DC6F362949DF07AAE103A5B484BC5383","fromMe":true,"participant":"972528884046:[email protected]"}'"} waha-1 | {"level":40,"time":1742071436793,"pid":1,"hostname":"9cd1c79f7a0a","session":"wab1","name":"NowebPersistentStore","msg":"got receipt update for non-existent message. key: '{"remoteJid":"[email protected]","id":"DC6F362949DF07AAE103A5B484BC5383","fromMe":true,"participant":"972528884046:[email protected]"}'"} waha-1 | {"level":30,"time":1742071446575,"pid":1,"hostname":"9cd1c79f7a0a","reqId":2496,"req":{"id":2496,"method":"GET","url":"/api/wab1/chats/1234567890XX%40c.us/messages?downloadMedia=true&limit=100","query":{"downloadMedia":"true","limit":"100"},"params":{"0":"api/wab1/chats/[email protected]/messages"}},"res":{"statusCode":null},"responseTime":60026,"msg":"request aborted"}
Hi!
Try fetching the list of messages without media (downloadMedia=False) and then proceed one by one with downloadMedia=True using
https://waha.devlike.pro/docs/how-to/receive-messages/#get-message-by-id
request aborted
Usually means that you reverse proxy drops the connection, WAHA would try to fetch all the media, there's no timeout in it.
i use the get message endpoint for one of the messages and i raise the timeout limit to 300 seconds but it still the same
it means the phone is offline or it doesn't have the message anymore maybe. Need to research it and send a error in this case not timeout 🤔
For now consider the media is not available if you don't get message by id in some period.