graphql-rust / juniper

GraphQL server library for Rust
Other
5.72k stars 425 forks source link

Use `actix-ws` for `juniper_actix` subscriptions #1197

Closed tyranron closed 1 year ago

tyranron commented 1 year ago

Follows #1191, #1186

Motivation

See https://github.com/graphql-rust/juniper/issues/1186#issuecomment-1730323445:

  1. Reimplement juniper_actix::subscritions via actorless actix-ws crate instead of the current actix-web-actors::ws one. The whole thing with actors cooperates very badly with juniper_graphql_ws state machine, introducing too excessive polling, which leads to panics and abnormal WebSocket closures instead of normal ones. It also gives a feeling of fighting with actors, trying to pair them with Stream/Sink, instead of easing it. So, the actorless actix-ws crate should go just fine, as we have in the juniper_warp crate.

Also, WebSocket connections are not closed normally in juniper_actix, due to panics:

Screenshot 2023-10-24 at 15 58 48 Screenshot 2023-10-24 at 15 59 41

Solution

Get rid of actix-web-actors::ws and use actix-ws crate instead.

Now, WebSocket connections are closing as expected:

Screenshot 2023-10-24 at 16 02 24 Screenshot 2023-10-24 at 16 02 44

Additionally