Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 27, 2025

Script save operations were failing with ERR_EMPTY_RESPONSE due to missing HTTP server timeout configuration and inadequate error handling in the file write path.

Changes

Server timeout configuration (back/services/http.ts)

  • Set requestTimeout: 300000ms, headersTimeout: 120000ms, keepAliveTimeout: 65000ms to prevent premature connection drops during file operations

Error handling improvements (back/api/script.ts, back/shared/utils.ts)

  • Added error logging in PUT /api/scripts endpoint
  • Restructured writeFileWithLock with proper try-catch-finally blocks for file handle and lock cleanup
  • Enhanced error messages with context (file path, operation type)
  • Ensured file handles always close and locks always release, even on failure

Type safety (back/shared/utils.ts)

  • Added explicit FileHandle type annotation
  • Changed nullable types to undefined for clearer semantics

Example

Before: File write errors could leave locks unreleased or file handles open, causing subsequent operations to hang or fail.

After:

try {
  await writeFileWithLock(filePath, content);
  return res.send({ code: 200 });
} catch (e) {
  logger.error('🔥 error saving script: %o', e);
  return next(e);  // Proper error propagation to middleware
}

Locks and file handles are guaranteed to be cleaned up via finally blocks, with distinct error messages for each failure point (create file, acquire lock, write file).

Original prompt

This section details on the original issue you should resolve

<issue_title>临时编辑脚本,无法保存,之前版本也出现过这种问题</issue_title>
<issue_description>### Qinglong version

v2.19.2-debian

Steps to reproduce

环境

  • 版本正式版 v2.19.2
  • 更新时间2025-06-27 23:59
  • docker 容器部署,使用debian镜像
Image Image

网络请求,脚本内容已删除,应该与内容无关,其他脚本也一样报错

Image

What is expected?

怎么解决这个问题,之前的版本也出现过这个问题

What is actually happening?

1

System Info

Any additional comments?

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link

vercel bot commented Dec 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
qinglong Ready Ready Preview, Comment Dec 27, 2025 8:51am
qinglong-back Ready Ready Preview, Comment Dec 27, 2025 8:51am

…t save operations

- Configure HTTP server timeouts (requestTimeout: 5min, headersTimeout: 2min, keepAliveTimeout: 65s)
- Add better error logging in PUT /scripts endpoint
- Improve writeFileWithLock error handling with descriptive messages and proper cleanup
- Ensure lock is always released even on error

Co-authored-by: whyour <[email protected]>
Copilot AI and others added 2 commits December 27, 2025 08:45
- Use finally block to ensure file handle is closed even on error
- Extract error messages properly using instanceof Error check
- Improve error message formatting for better debugging

Co-authored-by: whyour <[email protected]>
- Wrap fileHandle.close() in try-catch to prevent masking original errors
- Log close errors without throwing to preserve error context

Co-authored-by: whyour <[email protected]>
- Add explicit FileHandle type annotation for fileHandle variable
- Change fileHandle check from truthy to explicit undefined check
- Change release type from null to undefined for better type safety

Co-authored-by: whyour <[email protected]>
Copilot AI changed the title [WIP] Fix temporary edit script unable to save issue Fix ERR_EMPTY_RESPONSE on script save by configuring server timeouts and improving error handling Dec 27, 2025
Copilot AI requested a review from whyour December 27, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

临时编辑脚本,无法保存,之前版本也出现过这种问题

2 participants