Skip to content

Commit

Permalink
Fix memory leak due to repetitive registration of FastAPI routes
Browse files Browse the repository at this point in the history
  • Loading branch information
talsabagport committed Nov 12, 2024
1 parent 6aaaa28 commit 6fd921f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

## 0.13.1 (2024-11-12)


### Bug Fixes

- Fix memory leak due to repetitive registration of FastAPI routes


## 0.13.0 (2024-11-10)


Expand Down
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"
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 6fd921f

Please sign in to comment.