Skip to content

feat(server): abort request when timeout #1158

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

Merged
merged 2 commits into from
Apr 27, 2025

Conversation

Thrimbda
Copy link
Collaborator

No description provided.

@Thrimbda Thrimbda requested a review from Copilot April 27, 2025 05:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a feature to abort requests when they timeout and updates the Postgres connection method by replacing the pg Pool with the postgres package.

  • Aborts server requests on timeout by triggering the abort flag on the request context.
  • Replaces the pg connection logic with the postgres library and updates the query execution and cancellation logic using RxJS.

Reviewed Changes

Copilot reviewed 2 out of 6 changed files in this pull request and generated 1 comment.

File Description
libraries/protocol/src/server.ts Adds an abort signal (isAborted$) when a request times out.
apps/postgres-storage/src/index.ts Switches from pg Pool to postgres library and implements query cancellation via rxjs.
Files not reviewed (4)
  • apps/postgres-storage/package.json: Language not supported
  • common/changes/@yuants/app-postgres-storage/2025-04-27-05-19.json: Language not supported
  • common/changes/@yuants/protocol/2025-04-27-05-19.json: Language not supported
  • common/config/rush/pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

apps/postgres-storage/src/index.ts:51

  • Using 'sql.unsafe' may expose the application to SQL injection risks; ensure that 'msg.req.query' is properly sanitized or otherwise deemed safe for unsafe execution.
const query = sql.unsafe(msg.req.query);

@@ -310,6 +310,7 @@ export class TerminalServer {
timeout(60_000),
catchError((err) => {
console.info(formatTime(Date.now()), `ServerError`, JSON.stringify(message), err);
Copy link
Preview

Copilot AI Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding an inline comment to clarify that triggering the abort flag intentionally stops further processing on timeout; this will improve code readability and maintainability.

Suggested change
console.info(formatTime(Date.now()), `ServerError`, JSON.stringify(message), err);
console.info(formatTime(Date.now()), `ServerError`, JSON.stringify(message), err);
// Intentionally trigger the abort flag to stop further processing on timeout

Copilot uses AI. Check for mistakes.

@Thrimbda
Copy link
Collaborator Author

@Thrimbda Thrimbda enabled auto-merge (squash) April 27, 2025 05:37
@Thrimbda Thrimbda merged commit 5f9edac into No-Trade-No-Life:main Apr 27, 2025
1 check passed
@Thrimbda Thrimbda deleted the wsy/patch-1 branch April 27, 2025 05:44
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.

1 participant