Skip to content
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

fix: refresh oauth memory leak #16

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/algebra/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ impl Actor for RefreshActor {
fn started(&mut self, ctx: &mut Self::Context) {
tracing::info!("RefreshActor started with id {:?}", ctx.address());
}

fn stopped(&mut self, ctx: &mut Self::Context) {
tracing::info!("RefreshActor stopped with id {:?}", ctx.address());
}
}

impl Supervised for RefreshActor {}

impl Handler<Refresh> for RefreshActor {
type Result = ResponseFuture<Result<Unit, Error>>;
type Result = ResponseActFuture<Self, Result<Unit, Error>>;

fn handle(&mut self, msg: Refresh, _: &mut Self::Context) -> Self::Result {
fn handle(&mut self, msg: Refresh, _ctx: &mut Self::Context) -> Self::Result {
let refresh_before = Utc::now();
let refresh_after = refresh_before + Duration::minutes(msg.refresh_before_in_minutes());
tracing::info!(
Expand All @@ -62,7 +66,7 @@ impl Handler<Refresh> for RefreshActor {
let connections_store = self.connections.clone();
let oauths_store = self.oauths.clone();

Box::pin(async move {
let future = async move {
tracing::info!("Searching for connections to refresh");
let connections = connections_store
.get_by(&refresh_before, &refresh_after)
Expand Down Expand Up @@ -105,6 +109,16 @@ impl Handler<Refresh> for RefreshActor {
}
Err(err) => Err(InternalError::io_err(err.to_string().as_str(), None)),
}
})
}
.into_actor(self)
.map(|res, _act, ctx| match res {
Ok(_) => {
ctx.stop();
Ok(())
}
Err(e) => Err(e),
});

Box::pin(future)
}
}
10 changes: 10 additions & 0 deletions src/algebra/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ impl Actor for TriggerActor {
ctx.address()
);
}

fn stopped(&mut self, ctx: &mut Self::Context) {
let request_id = self.request_id.map(|id| id.to_string());

tracing::info!(
request_id = request_id.as_deref(),
"TriggerActor stopped with address: {:?}",
ctx.address()
);
}
}

impl Supervised for TriggerActor {}
Expand Down
Loading