Skip to content

Fix #207: avoid server stall when a client stops answering broadcasts - #208

Merged
dmercuriali merged 1 commit into
masterfrom
fix-207-expirer-blocks-slow-client-detection
Nov 5, 2026
Merged

dmercuriali merged 1 commit into
masterfrom
fix-207-expirer-blocks-slow-client-detection

Conversation

@diegosalvi

Copy link
Copy Markdown
Contributor

Fixes #207

Problem

The broadcast reply deadlines (slow client detection) were checked by cache-server-expire-thread, the same thread that invalidates TTL-expired entries, and only after waiting (CountDownLatch.await()) for those invalidations to complete.

When a client stopped answering, an expiration invalidation sent to it never completed: the expirer thread blocked forever, the deadlines were no longer checked, the slow client was never disconnected and every operation waiting for it hung, stalling the whole server.

Changes

CacheServer

  • Broadcast reply deadlines are checked by a dedicated thread (cache-server-idle-connections-thread) that never waits for cache operations.
  • The expirer no longer waits for the expiration invalidations. Keys whose expiration is in progress are tracked and skipped, so an invalidation stuck behind an application lock (which has no timeout) or a slow client only delays the expiration of its own key. At most 1000 new expirations are started on each run; there is no cap on in-flight ones, so stuck keys can never stop the expiration of the others.
  • Both background loops log and survive unexpected errors instead of dying silently.
  • Non positive expirer / idle connections check periods are rejected.

NettyChannel / NettyConnector

  • The wait for the socket close is bounded (blazingcache.nettychannel.closetimeout system property, default 10s). On timeout the wait is abandoned: the close is already scheduled and Netty completes it later.
  • No wait at all when invoked from the channel event loop, where Netty forbids blocking (e.g. SSL close_notify).
  • Pending reply callbacks are always failed on close, even if closing the socket fails.
  • close() runs exactly once, and the client no longer waits twice for the same socket.

ServerMain / server.properties

  • New settings expirer.period and idle.connections.check.period (default 1000 ms).

Tests

  • ExpirerBlockedBySlowClientTest: a client that never acks invalidations is disconnected and the expired entry is cleaned up (fails on master).
  • ExpirerBlockedByLockTest: an expired entry locked by a client does not block the expiration of other entries (fails on master).
  • CacheServerPeriodsConfigurationTest: periods validation.

apache-rat:check, spotbugs:check and the core/jcache test suites pass on JDK 11.

The broadcast reply deadlines (slow client detection) were checked by the
same thread that expires TTL entries, after waiting for the expiration
invalidations to complete. When a client stopped answering, an expiration
invalidation never completed, the expirer thread blocked forever and the
deadlines were no longer checked: the slow client was never disconnected
and every operation waiting for it hung, stalling the whole server.

CacheServer
- Check broadcast reply deadlines on a dedicated thread
  (cache-server-idle-connections-thread) which never waits for cache
  operations.
- The expirer no longer waits for the expiration invalidations: keys whose
  expiration is in progress are tracked and skipped, so an invalidation stuck
  behind an application lock (which has no timeout) or a slow client only
  delays the expiration of its own key. At most 1000 new expirations are
  started on each run.
- Both background loops survive unexpected errors instead of dying silently.
- Reject non positive expirer / idle connections check periods.

NettyChannel / NettyConnector
- Bound the wait for the socket close (blazingcache.nettychannel.closetimeout,
  default 10s) and never wait when invoked from the channel event loop, where
  Netty forbids blocking (e.g. SSL close_notify).
- Always fail the pending reply callbacks on close, even if closing the socket
  fails.
- Make close() run exactly once and avoid waiting twice for the same socket
  on the client side.

ServerMain
- New server.properties settings: expirer.period and
  idle.connections.check.period (default 1000 ms).

Tests
- ExpirerBlockedBySlowClientTest: a client never acking invalidations is
  disconnected and the expired entry cleaned up.
- ExpirerBlockedByLockTest: an expired entry locked by a client does not
  block the expiration of other entries.
- CacheServerPeriodsConfigurationTest: periods validation.

@dmercuriali dmercuriali left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@dmercuriali
dmercuriali merged commit 364c288 into master Nov 5, 2026
2 checks 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.

Self deadlock on the cache server when a client is irresponsive

2 participants