[Bug]: Crash on failure to download image file #1891

Closed
opened 2026-04-25 00:01:01 +02:00 by adam · 2 comments
Owner

Originally created by @nichwall on GitHub (Apr 17, 2024).

Describe the issue

When failing to download an image file during a single match operation, the server crashes. Originally posted by hjk321 in Discord. Not sure exactly what causes the failure.

Steps to reproduce the issue

  1. Failure to download a cover image.

Truncated error message

audiobookshelf-1  | [2024-04-16 23:19:48.688] INFO: [Audnexus] Searching for author "https://api.audnex.us/authors?name=the+forsaken+throne%3A+the+kingfountain+series%2C+book+6"
audiobookshelf-1  | [2024-04-16 23:20:10.456] ERROR: [fileUtils] Failed to download file "/metadata/items/77c10708-3f89-461a-a815-f0ffc5837299/cover" AxiosError: getaddrinfo EAI_AGAIN m.media-amazon.com
audiobookshelf-1  |     at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {
audiobookshelf-1  |   hostname: 'm.media-amazon.com',
audiobookshelf-1  |   syscall: 'getaddrinfo',
audiobookshelf-1  |   code: 'EAI_AGAIN',
audiobookshelf-1  |   errno: -3001,
audiobookshelf-1  |   config: {
audiobookshelf-1  |     transitional: {
audiobookshelf-1  |       silentJSONParsing: true,
audiobookshelf-1  |       forcedJSONParsing: true,
audiobookshelf-1  |       clarifyTimeoutError: false
audiobookshelf-1  |     },
audiobookshelf-1  |     adapter: [Function: httpAdapter],
audiobookshelf-1  |     transformRequest: [ [Function: transformRequest] ],
audiobookshelf-1  |     transformResponse: [ [Function: transformResponse] ],
audiobookshelf-1  |     timeout: 30000,
audiobookshelf-1  |     xsrfCookieName: 'XSRF-TOKEN',
audiobookshelf-1  |     xsrfHeaderName: 'X-XSRF-TOKEN',
audiobookshelf-1  |     maxContentLength: -1,
audiobookshelf-1  |     maxBodyLength: -1,
audiobookshelf-1  |     env: { FormData: [Function] },
audiobookshelf-1  |     validateStatus: [Function: validateStatus],
audiobookshelf-1  |     headers: {
audiobookshelf-1  |       Accept: 'application/json, text/plain, */*',
audiobookshelf-1  |       'User-Agent': 'axios/0.27.2'
audiobookshelf-1  |     },
audiobookshelf-1  |     url: 'https://m.media-amazon.com/images/I/91AVVZUfl9L.jpg',
audiobookshelf-1  |     method: 'get',
audiobookshelf-1  |     responseType: 'stream',

Audiobookshelf version

2.8.1

How are you running audiobookshelf?

Docker

Originally created by @nichwall on GitHub (Apr 17, 2024). ### Describe the issue When failing to download an image file during a single match operation, the server crashes. Originally posted by `hjk321` in Discord. Not sure exactly what causes the failure. ### Steps to reproduce the issue 1. Failure to download a cover image. Truncated error message ``` audiobookshelf-1 | [2024-04-16 23:19:48.688] INFO: [Audnexus] Searching for author "https://api.audnex.us/authors?name=the+forsaken+throne%3A+the+kingfountain+series%2C+book+6" audiobookshelf-1 | [2024-04-16 23:20:10.456] ERROR: [fileUtils] Failed to download file "/metadata/items/77c10708-3f89-461a-a815-f0ffc5837299/cover" AxiosError: getaddrinfo EAI_AGAIN m.media-amazon.com audiobookshelf-1 | at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) { audiobookshelf-1 | hostname: 'm.media-amazon.com', audiobookshelf-1 | syscall: 'getaddrinfo', audiobookshelf-1 | code: 'EAI_AGAIN', audiobookshelf-1 | errno: -3001, audiobookshelf-1 | config: { audiobookshelf-1 | transitional: { audiobookshelf-1 | silentJSONParsing: true, audiobookshelf-1 | forcedJSONParsing: true, audiobookshelf-1 | clarifyTimeoutError: false audiobookshelf-1 | }, audiobookshelf-1 | adapter: [Function: httpAdapter], audiobookshelf-1 | transformRequest: [ [Function: transformRequest] ], audiobookshelf-1 | transformResponse: [ [Function: transformResponse] ], audiobookshelf-1 | timeout: 30000, audiobookshelf-1 | xsrfCookieName: 'XSRF-TOKEN', audiobookshelf-1 | xsrfHeaderName: 'X-XSRF-TOKEN', audiobookshelf-1 | maxContentLength: -1, audiobookshelf-1 | maxBodyLength: -1, audiobookshelf-1 | env: { FormData: [Function] }, audiobookshelf-1 | validateStatus: [Function: validateStatus], audiobookshelf-1 | headers: { audiobookshelf-1 | Accept: 'application/json, text/plain, */*', audiobookshelf-1 | 'User-Agent': 'axios/0.27.2' audiobookshelf-1 | }, audiobookshelf-1 | url: 'https://m.media-amazon.com/images/I/91AVVZUfl9L.jpg', audiobookshelf-1 | method: 'get', audiobookshelf-1 | responseType: 'stream', ``` ### Audiobookshelf version 2.8.1 ### How are you running audiobookshelf? Docker
adam added the bug label 2026-04-25 00:01:01 +02:00
adam closed this issue 2026-04-25 00:01:01 +02:00
Author
Owner

@advplyr commented on GitHub (Apr 20, 2024):

I found the original post in Discord since that log isn't showing a crash. The exception was caught correctly in that part of the log but directly after that the crash happened.

With the updates I made a few months ago for crash logs the crashes will have log type FATAL.

audiobookshelf-1  | [2024-04-16 23:20:10.467] ERROR: [CoverManager] Download image file failed for "https://m.media-amazon.com/images/I/91AVVZUfl9L.jpg" getaddrinfo EAI_AGAIN m.media-amazon.com (CoverManager.js:129)
audiobookshelf-1  | [2024-04-16 23:20:10.526] INFO: [LibraryItem] Library item "77c10708-3f89-461a-a815-f0ffc5837299" updated
audiobookshelf-1  | [2024-04-16 23:20:10.530] FATAL: [Server] Unhandled rejection: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client, promise: Promise {
audiobookshelf-1  |   <rejected> Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
audiobookshelf-1  |       at ServerResponse.setHeader (node:_http_outgoing:652:11)
audiobookshelf-1  |       at ServerResponse.header (/node_modules/express/lib/response.js:794:10)
audiobookshelf-1  |       at ServerResponse.send (/node_modules/express/lib/response.js:174:12)
audiobookshelf-1  |       at ServerResponse.json (/node_modules/express/lib/response.js:278:15)
audiobookshelf-1  |       at ApiRouter.updateMedia (/server/controllers/LibraryItemController.js:172:9) {
audiobookshelf-1  |     code: 'ERR_HTTP_HEADERS_SENT'
audiobookshelf-1  |   }
audiobookshelf-1  | } (Server.js:164)

I tracked this one down to https://github.com/advplyr/audiobookshelf/pull/2573 where the response was sent as a 400 in uploadCover and we weren't checking if the response was already sent in updateMedia. I added a check for res.headersSent to handle that. For future reference @mikiher

@advplyr commented on GitHub (Apr 20, 2024): I found the original post in Discord since that log isn't showing a crash. The exception was caught correctly in that part of the log but directly after that the crash happened. With the updates I made a few months ago for crash logs the crashes will have log type `FATAL`. ```bash audiobookshelf-1 | [2024-04-16 23:20:10.467] ERROR: [CoverManager] Download image file failed for "https://m.media-amazon.com/images/I/91AVVZUfl9L.jpg" getaddrinfo EAI_AGAIN m.media-amazon.com (CoverManager.js:129) audiobookshelf-1 | [2024-04-16 23:20:10.526] INFO: [LibraryItem] Library item "77c10708-3f89-461a-a815-f0ffc5837299" updated audiobookshelf-1 | [2024-04-16 23:20:10.530] FATAL: [Server] Unhandled rejection: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client, promise: Promise { audiobookshelf-1 | <rejected> Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client audiobookshelf-1 | at ServerResponse.setHeader (node:_http_outgoing:652:11) audiobookshelf-1 | at ServerResponse.header (/node_modules/express/lib/response.js:794:10) audiobookshelf-1 | at ServerResponse.send (/node_modules/express/lib/response.js:174:12) audiobookshelf-1 | at ServerResponse.json (/node_modules/express/lib/response.js:278:15) audiobookshelf-1 | at ApiRouter.updateMedia (/server/controllers/LibraryItemController.js:172:9) { audiobookshelf-1 | code: 'ERR_HTTP_HEADERS_SENT' audiobookshelf-1 | } audiobookshelf-1 | } (Server.js:164) ``` I tracked this one down to https://github.com/advplyr/audiobookshelf/pull/2573 where the response was sent as a 400 in `uploadCover` and we weren't checking if the response was already sent in `updateMedia`. I added a check for `res.headersSent` to handle that. For future reference @mikiher
Author
Owner

@advplyr commented on GitHub (Apr 22, 2024):

Fixed in v2.9.0

@advplyr commented on GitHub (Apr 22, 2024): Fixed in [v2.9.0](https://github.com/advplyr/audiobookshelf/releases/tag/v2.9.0)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#1891