Reconnect to the Saturn server and time out requests #2

Merged
selimaj-dev merged 1 commits from reconnect-and-timeouts into master 2026-09-25 12:48:46 +00:00
Owner

Fixes saturnclientmc/saturnclient#4 and saturnclientmc/saturnclient#5.

Summary

  • session-java 0.2.0: dev.selimaj:session-java:0.2.0 from the Gitea package registry (selimaj-dev/session-java#2), replacing JitPack's com.github.selimaj-dev:session-java:0.1.6. It brings the lost-response fix, failing pending requests on close, onClose, request timeouts and serialized sends.
  • Reconnect (#4): ServiceClient now has one connect loop, running on a Saturn-Connect daemon thread.
    • When it runs: at startup, and again whenever the session closes. That covers server redeploys, network drops and ping timeouts.
    • Backoff: 1 s, 2 s, 4 s … capped at 60 s.
    • When it stops: only when retrying can't help, i.e. there's no Minecraft session or the server rejects the token (an errorresponse to auth).
    • Publishing the session: session is set only after auth succeeds, so nothing sends on an unauthenticated connection. isConnected() means "authenticated".
    • On each (re)connect:
      • owned cloaks and hats are replaced rather than appended
      • SaturnPlayer.clear() drops cached players, since they may have changed cosmetics meanwhile
      • notification handlers are registered on the new session
    • Race handling: a drop right after auth, before the connect loop finishes, still triggers a reconnect.
  • Timeouts (#5): every request times out after 10 s, and connecting times out after 10 s (it was 2 minutes × 5 attempts). A timed-out getPlayer fails like any other error, so SaturnPlayer retries it after 5 s instead of the worker hanging forever.
  • Cleanup:
    • onClientStopping is registered once, not on every auth.
    • Request callbacks use a local session reference instead of re-reading the field.
    • Errors are logged through Providers.saturn.logError instead of printStackTrace.
  • Dev: -Dsaturn.serverUri=ws://127.0.0.1:8080 points the client at a local server. The default is still production.

connectTimeout, connectMultiTimeout and authenticate are no longer public. Nothing else referenced them.

Testing

  • All 8 versions compile, resolving session-java 0.2.0 from the Gitea registry only (--refresh-dependencies, no mavenLocal).
  • Ran 1.21.11 with a real account against a local copy of the server (-Dsaturn.serverUri):
    • It authenticated.
    • When the server was stopped, the client logged "Disconnected … reconnecting" immediately and retried after 1 s, 2 s, 4 s and 8 s.
    • After the server was restarted, it re-authenticated with no user action.
  • Not covered:
    • a request timing out inside the real client (covered by session-java's tests)
    • the shutdown path
    • clicking through cosmetics after a reconnect

Merge this before the saturnclient PR that bumps the submodule and switches the build files.

🤖 Generated with Claude Code

Fixes saturnclientmc/saturnclient#4 and saturnclientmc/saturnclient#5. ## Summary - **session-java 0.2.0:** `dev.selimaj:session-java:0.2.0` from the Gitea package registry (selimaj-dev/session-java#2), replacing JitPack's `com.github.selimaj-dev:session-java:0.1.6`. It brings the lost-response fix, failing pending requests on close, `onClose`, request timeouts and serialized sends. - **Reconnect (#4):** `ServiceClient` now has one connect loop, running on a `Saturn-Connect` daemon thread. - **When it runs:** at startup, and again whenever the session closes. That covers server redeploys, network drops and ping timeouts. - **Backoff:** 1 s, 2 s, 4 s … capped at 60 s. - **When it stops:** only when retrying can't help, i.e. there's no Minecraft session or the server rejects the token (an `errorresponse` to `auth`). - **Publishing the session:** `session` is set only after `auth` succeeds, so nothing sends on an unauthenticated connection. `isConnected()` means "authenticated". - **On each (re)connect:** - owned cloaks and hats are **replaced** rather than appended - `SaturnPlayer.clear()` drops cached players, since they may have changed cosmetics meanwhile - notification handlers are registered on the new session - **Race handling:** a drop right after auth, before the connect loop finishes, still triggers a reconnect. - **Timeouts (#5):** every request times out after **10 s**, and connecting times out after **10 s** (it was 2 minutes × 5 attempts). A timed-out `getPlayer` fails like any other error, so `SaturnPlayer` retries it after 5 s instead of the worker hanging forever. - **Cleanup:** - `onClientStopping` is registered once, not on every auth. - Request callbacks use a local session reference instead of re-reading the field. - Errors are logged through `Providers.saturn.logError` instead of `printStackTrace`. - **Dev:** `-Dsaturn.serverUri=ws://127.0.0.1:8080` points the client at a local server. The default is still production. `connectTimeout`, `connectMultiTimeout` and `authenticate` are no longer public. Nothing else referenced them. ## Testing - All 8 versions compile, resolving `session-java` 0.2.0 from the Gitea registry only (`--refresh-dependencies`, no mavenLocal). - Ran 1.21.11 with a real account against a local copy of the server (`-Dsaturn.serverUri`): - It authenticated. - When the server was **stopped**, the client logged "Disconnected … reconnecting" immediately and retried after 1 s, 2 s, 4 s and 8 s. - After the server was **restarted**, it re-authenticated with no user action. - **Not covered:** - a request timing out inside the real client (covered by session-java's tests) - the shutdown path - clicking through cosmetics after a reconnect Merge this before the saturnclient PR that bumps the submodule and switches the build files. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
selimaj-dev added 1 commit 2026-09-25 12:46:32 +00:00
Move to session-java 0.2.0 (Gitea package registry) and rework
ServiceClient around a single connect loop:

- Reconnect with exponential backoff (1 s -> 60 s) when the connection
  drops, e.g. on every server redeploy; give up only when retrying cannot
  help (no Minecraft session, or the server rejects the token)
- Publish the session only after authentication succeeds, and replace
  (rather than append to) owned cosmetics and clear cached players on
  reconnect
- Time out every request after 10 s and connecting after 10 s, so a lost
  response can no longer hang the player-lookup worker forever
- Register onClientStopping once, and keep a local session reference in
  request callbacks
- Allow -Dsaturn.serverUri to point the client at a local server

Refs saturnclientmc/saturnclient#4, saturnclientmc/saturnclient#5

Co-Authored-By: Claude Opus 5.5 <[email protected]>
selimaj-dev merged commit 510760d590 into master 2026-09-25 12:48:46 +00:00
selimaj-dev deleted branch reconnect-and-timeouts 2026-09-25 12:48:49 +00:00
Sign in to join this conversation.