PhoenixSharp 2.0 is a ground-up hardening of the 1.x library: 29 commits closing every finding from a full-library audit, with the test suite growing from 220 to 375 tests, every behavioral change test-driven, and every commit adversarially reviewed before merge.
Highlights
- Full thread safety. All core state (socket lifecycle, push reply pipeline, heartbeats, presence, schedulers, callback registration) is now properly synchronized with documented semantics. Callbacks may fire on any thread — see the new Threading model section.
- No await-forever paths.
ConnectAsync,DisconnectAsync,JoinAsync,PushAsync,LeaveAsync, and the wait helpers complete (or fault with typed exceptions) in every reachable state — including disposal, mid-reconnect disconnects, custom server reply statuses, and throwing user callbacks. - Structured errors, visible by default. Typed exceptions (
PhoenixConnectionException,InvalidOperationExceptionfor misuse), a structuredPhoenixErroronOnError, a newOnUnhandledErrorsurface for contained failures, a redesignedILoggerwith sink-owned filtering, and shippedConsoleLogger/UnityLoggerimplementations. Silent failure is gone. - Resilient send policy. Send failures are contained and retried with an attempt cap — they no longer error channels, reset reconnect backoff, or fault connect waiters. Serializer failures are dropped poison; heartbeats are send-or-drop.
- Protocol tolerance. Custom reply statuses no longer break the reply pipeline; connection params are URL-encoded (base64 tokens work); V2 frames are validated;
Options.ParamsProviderenables fresh auth tokens on every reconnect. - Mobile performance. Steady-state dispatch allocations cut from 184 to 56 bytes/message (replies 288 → 104); presence sync 27% less garbage and 33% faster; cancelled timers release immediately. Allocation budgets are enforced by tests.
- Packaging. XML IntelliSense docs and SourceLink now ship in the NuGet package; the Unity package gains an engine-free core assembly with a separate auto-referenced
Phoenix.UnityLoggerassembly, and CI now compile-gates both Unity assembly shapes.
Breaking changes
2.0 is a breaking release. The Migration Guide covers every change with before/after snippets — the headline items:
ILoggeris a new two-method interface (IsEnabled+Logwith anException?parameter)Socket.OnErrordelivers aPhoenixErrorinstead of a string; Socket/Presence callback members are now C# eventsWebsocketConfigurationis an immutable class with PascalCase properties; theIWebsocketcontract is documentedPresence.Stateis a get-only snapshot property; presence callbacks match phoenix.js semantics exactly- Send/serialization failures surface through
OnErrorinstead of throwing synchronously - Connection params are snapshotted at construction and escaped exactly once (use
ParamsProviderfor live token refresh)
Upgrading
- Read the Migration Guide — compile-time breaks first, then runtime behavior changes.
- Unity consumers: the recommended NativeWebSocket adapter sample now requires NativeWebSocket 2.x and
Tick()must be called every frame (see the sample's notes on why).
Built with test-driven development and multi-agent adversarial review. Implementation by OpenAI Codex; orchestration and review by Claude.