Skip to content

Commit

Permalink
Fix memory leak of fastapi recurring setup
Browse files Browse the repository at this point in the history
  • Loading branch information
talsabagport committed Nov 11, 2024
1 parent 9a117a5 commit 35ef1d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion port_ocean/ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def __init__(
self.port_client, self.config.scheduled_resync_interval
)

self.app_initialized = False

def is_saas(self) -> bool:
return self.config.runtime == Runtime.Saas

Expand Down Expand Up @@ -112,7 +114,7 @@ async def execute_resync_all() -> None:
)
await repeated_function()

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
def initialize_app(self):
self.fast_api_app.include_router(self.integration_router, prefix="/integration")

@asynccontextmanager
Expand All @@ -129,4 +131,10 @@ async def lifecycle(_: FastAPI) -> AsyncIterator[None]:
signal_handler.exit()

self.fast_api_app.router.lifespan_context = lifecycle
self.app_initialized = True

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if not self.app_initialized:
self.initialize_app()

await self.fast_api_app(scope, receive, send)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "port-ocean"
version = "0.13.0"
version = "0.13.1-dev01"
description = "Port Ocean is a CLI tool for managing your Port projects."
readme = "README.md"
homepage = "https://app.getport.io"
Expand Down

0 comments on commit 35ef1d3

Please sign in to comment.