{"record":{"id":"9b36bba9e48d2658","repo":"apache/dolphinscheduler","slug":"download-the-resource-file-fileabsolutepath-fai","errorCode":null,"errorMessage":"Download the resource file: {fileAbsolutePath} failed","messagePattern":"Download the resource file: (.+?) failed","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java","lineNumber":380,"sourceCode":"                .build();\n        downloadFileDtoValidator.validate(downloadFileDto);\n\n        String fileName = new File(downloadFileDto.getFileAbsolutePath()).getName();\n        String localTmpFileAbsolutePath = FileUtils.getDownloadFilename(fileName);\n\n        try {\n            storageOperator.download(downloadFileRequest.getFileAbsolutePath(), localTmpFileAbsolutePath, true);\n            int length = (int) new File(localTmpFileAbsolutePath).length();\n            ApiServerMetrics.recordApiResourceDownloadSize(length);\n\n            response.reset();\n            response.setContentType(\"application/octet-stream\");\n            response.setCharacterEncoding(\"utf-8\");\n            response.setContentLength(length);\n            response.setHeader(\"Content-Disposition\", \"attachment;filename=\" + fileName);\n            Files.copy(Paths.get(localTmpFileAbsolutePath), response.getOutputStream());\n        } catch (Exception e) {\n            throw new ServiceException(\n                    \"Download the resource file: \" + downloadFileRequest.getFileAbsolutePath() + \" failed\", e);\n        } finally {\n            FileUtils.deleteFile(localTmpFileAbsolutePath);\n        }\n    }\n\n    @Override\n    public StorageEntity queryFileStatus(String userName, String fileAbsolutePath) {\n        return storageOperator.getStorageEntity(fileAbsolutePath);\n    }\n\n    @Override\n    public String queryResourceBaseDir(User loginUser, ResourceType type) {\n\n        User user = userDao.queryById(loginUser.getId());\n        if (user == null) {\n            throw new ServiceException(Status.USER_NOT_EXIST);\n        }","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L362-L398","documentation":"ResourcesServiceImpl.downloadResource wraps any exception while streaming a resource file to the HTTP response into ServiceException(\"Download the resource file: <path> failed\", e). It copies a local tmp file (previously fetched from storage) to the servlet output stream; failures reading the file, storage retrieval errors, or broken client connections surface here. The tmp file is deleted in finally regardless of outcome.","triggerScenarios":"Downloading a resource whose backing object is missing from HDFS/S3; local tmp write/read failure (disk full, permissions); client disconnects mid-copy causing IOException on the output stream.","commonSituations":"Storage object deleted externally or by retention policy while metadata row remains; browser canceled download causing broken-pipe; API server cannot reach storage cluster.","solutions":["Check the wrapped cause in server logs: a missing storage object means the resource metadata is stale — re-upload or remove the resource entry.","Verify storage connectivity and credentials from the API server, then retry the download.","If the cause is a client disconnect (broken pipe), it is benign — retry the download from a stable connection."],"exampleFix":"// before: stale resource entry pointing to deleted S3 object\nGET /resources/download -> \"Download the resource file: /wf/script.sql failed\"\n\n// after: re-upload the file via the resource center, then download succeeds","handlingStrategy":"try-catch","validationCode":"// verify the resource exists in storage before downloading\n// e.g. storageOperator.exists(resourceAbsolutePath) == true","typeGuard":null,"tryCatchPattern":"try {\n    resourcesService.downloadResource(response, request);\n} catch (ServiceException e) {\n    if (e.getCause() instanceof NoSuchFileException) {\n        // re-upload or remove stale resource entry\n    }\n}","preventionTips":["Keep storage objects and resource metadata in sync","Warn users not to cancel downloads abruptly in automation","Monitor storage connectivity from API servers"],"tags":["resources","download","storage","io"],"backgroundTag":"file-read-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}