I was doing this: Mythic/server.py at 9085d1d3edcb78573e55a91674057dd7733f1544 · its-a-feature/Mythic · GitHub and initializing here https://github.com/its-a-feature/Mythic/blob/9085d1d3edcb78573e55a91674057dd7733f1544/mythic-docker/app/init.py where I did the create_server
method, but my project can have like 300+ things connecting in at a time, so I gotta optimize it better to leverage the resources of where it’s deployed while still allowing my async database connections to work in the workers. Similarly, I leverage sanic-jwt and sanic-wtf with some in-memory tracking that I now need to store in a database since there’s no shared memory.
I’ve updated the server file to:
from app import (
mythic,
dbloop,
listen_ip,
listen_port,
keep_logs,
debugging_enabled,
)
import asyncio
from app.api.rabbitmq_api import start_listening
import traceback
if __name__ == "__main__":
try:
asyncio.set_event_loop(dbloop)
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(start_listening())
mythic.run(host=listen_ip, port=int(listen_port), debug=debugging_enabled, access_log=keep_logs, workers=4)
except Exception as e:
print(str(e))
loop.stop()
except Exception as e:
traceback.print_exc()
to allow me to use the workers and I added a before_server_start
to handle the database connections so that each worker is able to connect to the database loop properly:
@mythic.listener("before_server_start")
async def setup_initial_info(sanic, loop):
app.db_objects = Manager(mythic_db, loop=loop)
await mythic_db.connect_async(loop=loop)
app.db_objects.database.allow_sync = logging.WARNING
await initial_setup()
await app.api.rabbitmq_api.start_listening()
however, I’m still running into issues with what i thought was shared data. For example, in that init.py file I have a mythic.config["variable"] = "value"
which doesn’t appear to be shared amongst all the workers (csrf failed when run with workers · Issue #16 · pyx/sanic-wtf · GitHub)