# Error 23 Fix – Session Migration Patch

## Overview
This patch addresses **Error 23** that occurs when transitioning from the avatar screen to the city screen. The error is caused by a session migration failure between the city and lot servers during reconnection attempts.

## Problem Description

### Symptoms
– Error 23 appears when trying to go from avatar screen to city screen
– Client shows “Network Error” dialog with error code 23
– Server logs show “Rejected migration: could not find session for userID X”

### Root Cause
The issue occurs due to a race condition in session management:

1. **Normal Flow**: Avatar leaves lot → lot server returns claim to city server → client reconnects to city
2. **The Problem**: City server cleans up the session too quickly (within milliseconds) before the client can reconnect
3. **Result**: Client attempts session migration but server can’t find the session → Error 23

### Technical Details
– Error 23 is triggered in `CityConnectionRegulator.cs` during “UnexpectedDisconnect” state
– Session cleanup happens in `VoltronConnectionLifecycleHandler.cs` immediately after disconnection
– Client reconnection attempts happen with only 1-second delays, creating pressure on server

## Files Modified

### 1. **TSOClient/NSO.Content.TSO/Content/UI/uitext/english.dir/_f222_networkstrings.cst** *(NEW)*
“`
1 ^Network Error^
2 ^A network error has occurred (Error %d). The connection to the server has been lost. Please check your internet connection and try again.^
“`
**Purpose**: Provides proper error messages for network errors instead of “***MISSING***” text.

### 2. **TSOClient/NSO.Server/Servers/City/Handlers/VoltronConnectionLifecycleHandler.cs**
**Changes**:
– Added `using NLog;` and `using System.Threading.Tasks;`
– Added static logger: `private static Logger LOG = LogManager.GetCurrentClassLogger();`
– **Key Fix**: Added 5-second delay before session cleanup in `SessionClosed()` method
– Added logging to track when session cleanup is cancelled due to reconnection

**Before**:
“`csharp
Liveness.EnqueueChange(() => {
if (Sessions.GetByAvatarId(voltronSession.AvatarId)?.Connected == true) return;
// immediate cleanup
});
“`

**After**:
“`csharp
Task.Delay(5000).ContinueWith(_ => {
Liveness.EnqueueChange(() => {
var existingSession = Sessions.GetByAvatarId(voltronSession.AvatarId);
if (existingSession?.Connected == true)
{
LOG.Info($”Session cleanup cancelled for avatar {voltronSession.AvatarId} – session still connected”);
return;
}
// cleanup after delay
});
});
“`

### 3. **TSOClient/tso.client/Regulators/CityConnectionRegulator.cs**
**Changes**:
– Modified `ReestablishFail` case to use progressive delays (2-8 seconds) instead of fixed 1-second delay
– Reduces server load and gives more time for session cleanup

**Before**:
“`csharp
GameThread.SetTimeout(() => {
if (CurrentState?.Name == “ReestablishFail”) AsyncTransition(“Reestablish”);
}, 1000); // Fixed 1-second delay
“`

**After**:
“`csharp
var delay = Math.Min(2000 + (ReestablishAttempt * 1000), 8000); // 2-8 second progressive delay
GameThread.SetTimeout(() => {
if (CurrentState?.Name == “ReestablishFail”) AsyncTransition(“Reestablish”);
}, delay);
“`

### 4. **TSOClient/FSO.Server/Framework/Aries/AbstractAriesServer.cs**
**Changes**:
– Enhanced logging in `AttemptMigration()` to show active session count when migration fails
– Helps with debugging session management issues

## Installation Instructions

1. **Apply the patch files** to your FreeSO server installation
2. **Restart the server** to load the changes
3. **Test the fix** by attempting the avatar → city transition

## Expected Behavior After Patch

### Successful Case
1. Avatar leaves lot
2. 5-second grace period allows for clean session transition
3. Client reconnects successfully using session migration
4. No Error 23 occurs

### If Issues Persist
– Enhanced logging will provide more detailed information about session states
– Progressive reconnection delays reduce server stress
– Proper error messages will be displayed instead of missing text

## Monitoring

After applying the patch, monitor server logs for:
– `”Session cleanup cancelled for avatar X – session still connected”` – indicates the fix is working
– `”Rejected migration: could not find session for userID X. Active sessions: Y”` – shows session count during failures
– Reduced frequency of migration rejection messages

## Rollback Instructions

If issues occur, you can rollback by:
1. Reverting the three modified files to their original state
2. Removing the `_f222_networkstrings.cst` file
3. Restarting the server

## Technical Notes

– **Session Timeout**: The 5-second delay is conservative and shouldn’t affect normal gameplay
– **Progressive Delays**: Client reconnection delays scale from 2-8 seconds to reduce server load
– **Backward Compatibility**: Changes are fully backward compatible with existing clients
– **Performance Impact**: Minimal – only affects disconnection scenarios

## Testing Recommendations

1. Test normal avatar → city transitions
2. Test lot → city transitions
3. Test network interruption scenarios
4. Monitor server logs for session migration patterns
5. Verify error messages display properly



**Patch Version**: 1.0
**Date**: 2025-08-13
**Compatibility**: FreeSO Server & Client
**Risk Level**: Low (Conservative changes with fallbacks)