1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Fix supysonic-server with gunicorn creating the application too early

Was causing SQL connection issues when using forked workers

Closes #241
This commit is contained in:
Alban Féron 2023-01-16 22:10:39 +01:00
parent be6b617e60
commit 36efefcda6
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
5 changed files with 19 additions and 21 deletions

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2021 Alban 'spl0k' Féron # Copyright (C) 2021-2023 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -13,7 +13,6 @@ from click import command, option, Option
from click.exceptions import UsageError, ClickException from click.exceptions import UsageError, ClickException
from click.types import Choice from click.types import Choice
from ..web import create_application
_servers = [ _servers = [
e.name[:-3] e.name[:-3]
@ -121,7 +120,6 @@ def main(server, host, port, socket, processes, threads):
host = None host = None
port = None port = None
app = create_application()
server( server(
app, host=host, port=port, socket=socket, processes=processes, threads=threads host=host, port=port, socket=socket, processes=processes, threads=threads
).run() ).run()

View File

@ -1,19 +1,19 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2021 Alban 'spl0k' Féron # Copyright (C) 2021-2023 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from ..web import create_application
class BaseServer(metaclass=ABCMeta): class BaseServer(metaclass=ABCMeta):
def __init__( def __init__(
self, app, *, host=None, port=None, socket=None, processes=None, threads=None self, *, host=None, port=None, socket=None, processes=None, threads=None
): ):
self._app = app
self._host = host self._host = host
self._port = port self._port = port
self._socket = socket self._socket = socket
@ -28,5 +28,8 @@ class BaseServer(metaclass=ABCMeta):
def _run(self, **kwargs): def _run(self, **kwargs):
... ...
def _load_app(self):
return create_application()
def run(self): def run(self):
self._run(**self._build_kwargs()) self._run(**self._build_kwargs())

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2021 Alban 'spl0k' Féron # Copyright (C) 2021-2023 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -16,7 +16,7 @@ from ._base import BaseServer
class GeventServer(BaseServer): class GeventServer(BaseServer):
def _build_kwargs(self): def _build_kwargs(self):
rv = {"application": self._app} rv = {"application": self._load_app()}
if self._socket is not None: if self._socket is not None:
if os.path.exists(self._socket): if os.path.exists(self._socket):

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2021 Alban 'spl0k' Féron # Copyright (C) 2021-2023 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -11,15 +11,11 @@ from ._base import BaseServer
class GunicornApp(BaseApplication): class GunicornApp(BaseApplication):
def __init__(self, app, **config): def __init__(self, **config):
self.__app = app
self.__config = config self.__config = config
super().__init__() super().__init__()
def load(self):
return self.__app
def load_config(self): def load_config(self):
socket = self.__config["socket"] socket = self.__config["socket"]
host = self.__config["host"] host = self.__config["host"]
@ -39,9 +35,10 @@ class GunicornApp(BaseApplication):
class GunicornServer(BaseServer): class GunicornServer(BaseServer):
def __init__(self, app, **kwargs): def __init__(self, **kwargs):
super().__init__(app, **kwargs) super().__init__(**kwargs)
self.__server = GunicornApp(app, **kwargs) self.__server = GunicornApp(**kwargs)
self.__server.load = self._load_app
def _build_kwargs(self): def _build_kwargs(self):
return {} return {}

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2021 Alban 'spl0k' Féron # Copyright (C) 2021-2023 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -12,7 +12,7 @@ from ._base import BaseServer
class WaitressServer(BaseServer): class WaitressServer(BaseServer):
def _build_kwargs(self): def _build_kwargs(self):
rv = {"app": self._app} rv = {"app": self._load_app()}
if self._host is not None: if self._host is not None:
rv["host"] = self._host rv["host"] = self._host