Skip to content

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

Merged
jasonbosco merged 4 commits intotypesense:masterfrom
tharropoulos:abort-signals
Dec 17, 2024
Merged

Fix node health tracking for aborted requests in cluster configuration#253
jasonbosco merged 4 commits intotypesense:masterfrom
tharropoulos:abort-signals

Conversation

@tharropoulos
Copy link
Copy Markdown
Collaborator

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
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