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

Keep long-running tasks alive #1725

Merged
merged 4 commits into from
Dec 13, 2023
Merged

Keep long-running tasks alive #1725

merged 4 commits into from
Dec 13, 2023

Conversation

luckysori
Copy link
Contributor

Inspired by #1724.

@luckysori luckysori self-assigned this Dec 12, 2023
Comment on lines 73 to 79
let mut conn = match pool.get() {
Ok(conn) => conn,
Err(e) => {
tracing::error!("Failed to get DB connection: {e:#}");
continue;
},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be cleaner here to wrap the inside of the while with a try block (idk if stable, we could use an async block/closure instead possibly)? that way, ? would only bubble up to that point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try would be super cool, but it's not stable.

I wasn't gonna bother originally, but since you mention it I can just extract the inside of the while loop into a function, like in all the other places where I fixed this.

Copy link
Contributor Author

@luckysori luckysori Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this force-push diff.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, that works too!

Comment on lines +164 to +166
let mut conn = spawn_blocking(move || pool.get())
.await
.expect("task to complete")?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we spawn_blocking here but not elsewhere? Additionally, can we not use a native async connection pool if this is a big issue?

Copy link
Contributor Author

@luckysori luckysori Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we spawn_blocking here but not elsewhere?

What do you mean by "elsewhere"? In this PR I have tried to consistently use spawn_blocking when calling pool.get().

It's very possible that we aren't doing this consistently, but we should because get blocks until the connection is retrieved or until a timeout expires.

Additionally, can we not use a native async connection pool if this is a big issue?

Yep, we can, although we didn't prioritise it thus far. It looks like we could use https://github.com/djc/bb8.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "elsewhere"? In this PR I have tried to consistently use spawn_blocking when calling pool.get().

My mistake, maybe I was checking the deleted and not added part 😅

Base automatically changed from fix/supervise-coordinator-trading to main December 13, 2023 01:43
Before we would end up bubbling up the error on `pool.get()`, which
would silently break out of the loop, so we would stop processin new
`OrderbookMessage`s.
Before we would end up bubbling up the error on `pool.get()`, which
would silently break out of the loop, so we would stop processing new
`NewUserMessage`s.
Before we would end up bubbling up the error on `pool.get()`, which
would silently break out of the loop, so we would stop processing new
`NewUserMessage`s.
Before we would end up bubbling up the error on `pool.get()`, which
would silently break out of the loop, so we would stop processin new
`NewUserMessage`s.
Copy link
Contributor

@bonomat bonomat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@luckysori luckysori added this pull request to the merge queue Dec 13, 2023
Merged via the queue into main with commit d21d7ad Dec 13, 2023
9 checks passed
@luckysori luckysori deleted the fix/keep-tasks-alive branch December 13, 2023 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants