-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: XRay Integration to Full Async with Enhanced Concurrency and Stability #67
base: master
Are you sure you want to change the base?
Conversation
- Replaces threading with asyncio for process management and log handling. - Uses asyncio.subprocess for non-blocking process interaction. - Adds an asyncio.Event for signaling Xray startup completion. - Improves error handling and timeout management during startup, shutdown, and restart. - Adds a separate task for processing logs and distributing them to clients. - Cancels log processing task on shutdown to prevent resource leaks. - Improved process termination with fallback to kill if necessary.
- Migrates Service class methods to be fully asynchronous. - Introduces locks (`_conn_lock`, `_core_lock`) for thread-safe access to shared resources. - Improves WebSocket log streaming with batching and error handling. - Adds a shutdown event handler to stop XRayCore on application shutdown. - Simplifies start/stop/restart logic using asyncio. - Removes blocking `time.sleep` calls in favor of `asyncio.sleep`. - Improved WebSocket connection management and graceful closure.
Change target branch to dev |
There is no dev branch in node |
It takes careful testing because the change is too big. Should gather some feedback before taking PR, I think. |
if you use a old marzban it raise an error
i cant test with ur pr |
Hmm. This is very strange. It's a normal warning that asks to generate a certificate with |
This Pull Request makes a significant change to the service architecture, moving it completely to an asynchronous operating model. This change is aimed at improving performance, scalability and reliability.
This change is intended to increase the stability of the nodes.
Key Changes and Improvements:
xray.py
XRayCore
with anasyncio
-based approach.asyncio.create_subprocess_exec
for non-blocking interaction with the XRay process.asyncio.Event
(_start_event
) to signal XRay startup completion, replacing the previous blocking polling mechanism._log_processor_task
) for processing logs and distributing them to panel, avoiding blocking the main event loop.kill()
if necessary.rest_service.py
All methods of the Service class are now fully asynchronous, avoiding I/O locks.
Improved handling of WebSocket logs:
Added an
@app.on_event("shutdown")
handler to ensure that theXRayCore
is stopped cleanly when the FastAPI application shuts down. This prevents resource leaks and ensures proper termination of the XRay process.These changes result in significant improvements in node performance and responsiveness, especially under load. The elimination of blocking operations allows FastAPI to efficiently handle requests and WebSocket connections.
The changes do not affect API backward compatibility.
TESTING HAS NOT BEEN CONDUCTED. Thorough testing is required.