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

Making the chat server an actor. #2793

Merged
merged 9 commits into from Apr 13, 2023
Merged

Making the chat server an actor. #2793

merged 9 commits into from Apr 13, 2023

Conversation

Copy link
Member Author

@dessalines dessalines left a comment

Choose a reason for hiding this comment

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

The comments in the api_routes_websocket.rs file are the main thing to look at, everything else is boilerplate.

src/api_routes_websocket.rs Show resolved Hide resolved
src/api_routes_websocket.rs Outdated Show resolved Hide resolved
@dessalines dessalines marked this pull request as ready for review March 30, 2023 21:16
@dessalines dessalines requested a review from Nutomic March 30, 2023 21:19
context: ContextData<LemmyContext>,
) -> Result<String, LemmyError> {
let rate_limiter = context.settings_updated_channel();
Copy link
Member Author

Choose a reason for hiding this comment

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

The RateLimitCell was already in the context, so I hope its okay to do this.

@dessalines
Copy link
Member Author

Ugh, I can't figure out why this is failing. It passes fine locally. https://woodpecker.join-lemmy.org/LemmyNet/lemmy/pipeline/89/12

@Nutomic
Copy link
Member

Nutomic commented Apr 6, 2023

The same error also happened in the PR to enable Woodpecker. So its somehow related to it. I would try to debug it in another branch by disabling all other CI steps and logging the full HTTP response thats causing the error.

"Websocket join with IP: {} has been rate limited.",
&client_ip
);
return Ok(HttpResponse::Unauthorized().finish());
Copy link
Member

Choose a reason for hiding this comment

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

Use HTTP 429, otherwise its just confusing.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429

context: web::Data<LemmyContext>,
rate_limiter: web::Data<RateLimitCell>,
/// How often heartbeat pings are sent
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
Copy link
Member

Choose a reason for hiding this comment

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

This seems way too much, especially for mobile. Isnt 30 or 60 seconds enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Not sure where you see 30 and 60, the first answer says heartbeat interval = 25s and heartbeat timeout = 60s.

src/api_routes_websocket.rs Outdated Show resolved Hide resolved
src/api_routes_websocket.rs Outdated Show resolved Hide resolved

impl LemmyContext {
#[tracing::instrument(skip_all)]
pub async fn send_post_ws_message(
Copy link
Member

Choose a reason for hiding this comment

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

Good idea to move these methods into LemmyContext. But leave the generic parameter like before, its annoying to have to_string() all over the place.

Copy link
Member Author

Choose a reason for hiding this comment

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

The generic op was way too complicated, mainly because for some reason the WebSocketOperation is split into 3 different enums. There was some hacks that I was able to remove by doing this.

Copy link
Member

Choose a reason for hiding this comment

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

Which hacks? I think the generics are way cleaner on the call side, but maybe not in the websocket code itself.

Copy link
Member

@Nutomic Nutomic Apr 11, 2023

Choose a reason for hiding this comment

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

Another approach you can use is to take a generic param like <OP: Into<String>>. Then you can treat it as string in the websocket code, while call sites dont have to put to_string() everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

I found a way to do it, I'll have this uploaded soon.

@dessalines
Copy link
Member Author

Aaaand woodpecker is now passing for no apparent reason lol. I'll take it.

@dessalines dessalines requested a review from Nutomic April 12, 2023 23:50
@Nutomic Nutomic enabled auto-merge (squash) April 13, 2023 10:14
@Nutomic Nutomic merged commit 63f54a3 into main Apr 13, 2023
1 check passed
dessalines added a commit that referenced this pull request Apr 26, 2023
* Making the chat server an actor.

- Fixes #2778
- #2787

* Forgot to add handlers folder.

* Some cleanup.

* Forgot to remove a comment.

* Address PR comments.

* Using ToString for enum operations.
dessalines added a commit that referenced this pull request May 4, 2023
* Making the chat server an actor.

- Fixes #2778
- #2787

* Forgot to add handlers folder.

* Some cleanup.

* Forgot to remove a comment.

* Address PR comments.

* Using ToString for enum operations.
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.

Memory leak causing server crashes
2 participants