Skip to content

fix: add ApiClient.close() to clean up ThreadLocal state on thread reuse#1694

Open
prachi-okta wants to merge 1 commit into
masterfrom
fix/api-client-clear-thread-context
Open

fix: add ApiClient.close() to clean up ThreadLocal state on thread reuse#1694
prachi-okta wants to merge 1 commit into
masterfrom
fix/api-client-clear-thread-context

Conversation

@prachi-okta
Copy link
Copy Markdown
Contributor

@prachi-okta prachi-okta commented Jun 3, 2026

Problem

ApiClient stores last response state in static ThreadLocal fields for backward compatibility with PaginationUtil. In thread-pool environments, threads are reused across requests, causing stale headers to leak between requests.

Changes

  • Added close() to clear lastStatusCode and lastResponseHeaders ThreadLocals for the current thread
  • Added unit tests in ApiClientTest (cleanup, idempotency, thread isolation)

Note: Only affects the deprecated PaginationUtil path — the new PagedIterable is already stateless.

@prachi-okta prachi-okta force-pushed the fix/api-client-clear-thread-context branch 3 times, most recently from 33ba8e0 to 9271c44 Compare June 4, 2026 17:59
@prachi-okta prachi-okta changed the title fix: add ApiClient.clearThreadContext() to clean up ThreadLocal state fix: add ApiClient.close() to clean up ThreadLocal state on thread reuse Jun 4, 2026
@prachi-okta prachi-okta force-pushed the fix/api-client-clear-thread-context branch from 9271c44 to c44aacb Compare June 4, 2026 18:21
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