Proxy Lifecycle
Gate’s proxy goes through several distinct phases during its lifetime:- Initialization: Proxy is created with configuration
- Ready: Proxy starts listening for connections
- Running: Proxy handles player connections and server communication
- Pre-Shutdown: Proxy stops accepting new connections
- Shutdown: Proxy disconnects all players and cleans up resources
ReadyEvent
TheReadyEvent is fired once the proxy has successfully initialized and is ready to serve connections. This is the ideal place to perform post-initialization setup.
Event Structure
When It’s Fired
- After the proxy successfully binds to its listening address
- Before any player connections are accepted
- May be triggered multiple times on config reloads
Example Usage
Use Cases
- Database Initialization: Connect to databases or external services
- Dynamic Server Registration: Register backend servers programmatically
- Background Tasks: Start periodic tasks or workers
- Plugin Communication: Notify other systems that the proxy is online
- Metrics Collection: Initialize monitoring and metrics systems
PreShutdownEvent
ThePreShutdownEvent is fired after the proxy has stopped accepting new connections but before any players are disconnected. This is your last opportunity to interact with connected players.
Event Structure
When It’s Fired
- After the proxy stops accepting new connections
- Before any players are disconnected
- The proxy will wait for all event listeners to complete
Example Usage
Use Cases
- Player Transfer: Transfer players to another proxy instance
- Data Persistence: Save player data before disconnection
- Custom Disconnect Messages: Provide informative shutdown reasons
- Graceful Degradation: Notify external services of the shutdown
- Cleanup Preparation: Prepare for final cleanup operations
ShutdownEvent
TheShutdownEvent is fired after the proxy has stopped accepting connections and after PreShutdownEvent, but before the proxy process exits.
Event Structure
When It’s Fired
- After all players have been disconnected
- Before the proxy process terminates
- After
PreShutdownEventhas been processed
Example Usage
Use Cases
- Resource Cleanup: Close connections, file handles, and other resources
- Background Task Termination: Stop goroutines and worker pools
- Final Data Persistence: Save any remaining state to disk
- External Service Notification: Notify monitoring systems of shutdown
- Graceful Shutdown: Ensure proper cleanup of plugin dependencies
Complete Lifecycle Example
Here’s a comprehensive example showing how to use all lifecycle events together:Best Practices
1. Handle Initialization Failures
2. Use Timeouts for Cleanup
3. Handle Multiple Ready Events
SinceReadyEvent may fire multiple times during config reloads, ensure your initialization is idempotent:

