Skip to content
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

Fix node health tracking for aborted requests in cluster configuration #253

Merged
merged 4 commits into from
Dec 17, 2024

Conversation

tharropoulos
Copy link
Contributor

Change Summary

What is this?

When using Typesense in cluster configuration with request abortion enabled, the client was incorrectly marking healthy nodes as unhealthy when requests were intentionally aborted. This caused unnecessary node cycling and could degrade search performance. This change ensures that nodes remain correctly marked when requests are aborted, maintaining proper cluster health state.

Changes

Code Changes:

  1. In ApiCall.ts:

    • Added wasAborted flag to track request abortion state
    • Improved abortSignal typing from any to proper AbortSignal DOM type
    • Enhanced abort handler to set wasAborted flag when request is cancelled
    • Modified node health check logic to skip marking nodes unhealthy on aborted requests
    • Added early return with abort error to prevent unnecessary retries
  2. In ApiCall.spec.js:

    • Added test suite for abort behavior:
      • Test abort handling without marking nodes unhealthy
      • Test proper node health tracking with mixed aborted/failed requests

Documentation Updates:

  1. Type Definitions:
    • Improved TypeScript definitions for abort signal handling
    • Added proper event typing for abort listeners

Context

This fixes the issue reported by @jonatansberg in #251 where nodes were being incorrectly marked as unhealthy when requests were intentionally aborted using AbortController, causing unnecessary node cycling in cluster configurations.

PR Checklist

* Add wasAborted flag to track abort state across request lifecycle
* Fix AbortSignal type definition to use proper DOM Event types
* Improve abort handler to prevent marking nodes as unhealthy when request
  is aborted
* Add tests for abort behavior with multiple nodes
* Fix error handling to return abort error instead of retrying on aborted
  requests
@jasonbosco jasonbosco merged commit 191b66a into typesense:master Dec 17, 2024
1 check passed
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