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 shutdown #2400

Merged
merged 7 commits into from
Apr 28, 2023
Merged

Fix shutdown #2400

merged 7 commits into from
Apr 28, 2023

Conversation

kangalio
Copy link
Collaborator

Calling shutdown was broken:

image

This PR fixes it.

The following text is taken from a commit description:

Previous execution path of ShardManager::shutdown:

ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return

New execution path:

ShardManager::shutdown()
calls Shard::shutdown()

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a shard: Arc<Mutex<Shard>> field to ShardRunnerInfo (ShardManager contains a runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an Arc<Mutex<Shard>> too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple shutdown function on Shard, which is called directly by ShardManager.

Previous execution path of ShardManager::shutdown:

```
ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return
```

New execution path:

```
ShardManager::shutdown()
calls Shard::shutdown()
```

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a `shard: Arc<Mutex<Shard>>` field to `ShardRunnerInfo` (`ShardManager` contains a `runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>`). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an `Arc<Mutex<Shard>>` too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple `shutdown` function on `Shard`, which is called directly by `ShardManager`.
@github-actions github-actions bot added examples Related to Serenity's examples. gateway Related to the `gateway` module. labels Apr 25, 2023
@arqunis arqunis added fix A solution to an existing bug. breaking change The public API is changed, resulting in miscompilations or unexpected new behaviour for users labels Apr 28, 2023
@arqunis arqunis merged commit 548976a into serenity-rs:next Apr 28, 2023
mkrasnitski pushed a commit to mkrasnitski/serenity that referenced this pull request May 18, 2023
Previous execution path of ShardManager::shutdown:

```
ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return
```

New execution path:

```
ShardManager::shutdown()
calls Shard::shutdown()
```

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a `shard: Arc<Mutex<Shard>>` field to `ShardRunnerInfo` (`ShardManager` contains a `runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>`). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an `Arc<Mutex<Shard>>` too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple `shutdown` function on `Shard`, which is called directly by `ShardManager`.
mkrasnitski pushed a commit to mkrasnitski/serenity that referenced this pull request May 19, 2023
Previous execution path of ShardManager::shutdown:

```
ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return
```

New execution path:

```
ShardManager::shutdown()
calls Shard::shutdown()
```

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a `shard: Arc<Mutex<Shard>>` field to `ShardRunnerInfo` (`ShardManager` contains a `runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>`). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an `Arc<Mutex<Shard>>` too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple `shutdown` function on `Shard`, which is called directly by `ShardManager`.
mkrasnitski pushed a commit to mkrasnitski/serenity that referenced this pull request May 30, 2023
Previous execution path of ShardManager::shutdown:

```
ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return
```

New execution path:

```
ShardManager::shutdown()
calls Shard::shutdown()
```

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a `shard: Arc<Mutex<Shard>>` field to `ShardRunnerInfo` (`ShardManager` contains a `runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>`). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an `Arc<Mutex<Shard>>` too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple `shutdown` function on `Shard`, which is called directly by `ShardManager`.
mkrasnitski added a commit to mkrasnitski/serenity that referenced this pull request Jun 21, 2023
mkrasnitski added a commit to mkrasnitski/serenity that referenced this pull request Jul 1, 2023
@mkrasnitski mkrasnitski mentioned this pull request Jul 6, 2023
arqunis pushed a commit to arqunis/serenity that referenced this pull request Jul 6, 2023
mkrasnitski pushed a commit to mkrasnitski/serenity that referenced this pull request Sep 21, 2023
Previous execution path of ShardManager::shutdown:

```
ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return
```

New execution path:

```
ShardManager::shutdown()
calls Shard::shutdown()
```

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a `shard: Arc<Mutex<Shard>>` field to `ShardRunnerInfo` (`ShardManager` contains a `runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>`). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an `Arc<Mutex<Shard>>` too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple `shutdown` function on `Shard`, which is called directly by `ShardManager`.
mkrasnitski added a commit to mkrasnitski/serenity that referenced this pull request Sep 21, 2023
mkrasnitski pushed a commit to mkrasnitski/serenity that referenced this pull request Oct 17, 2023
Previous execution path of ShardManager::shutdown:

```
ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return
```

New execution path:

```
ShardManager::shutdown()
calls Shard::shutdown()
```

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a `shard: Arc<Mutex<Shard>>` field to `ShardRunnerInfo` (`ShardManager` contains a `runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>`). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an `Arc<Mutex<Shard>>` too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple `shutdown` function on `Shard`, which is called directly by `ShardManager`.
mkrasnitski added a commit to mkrasnitski/serenity that referenced this pull request Oct 17, 2023
mkrasnitski pushed a commit to mkrasnitski/serenity that referenced this pull request Oct 24, 2023
Previous execution path of ShardManager::shutdown:

```
ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return
```

New execution path:

```
ShardManager::shutdown()
calls Shard::shutdown()
```

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a `shard: Arc<Mutex<Shard>>` field to `ShardRunnerInfo` (`ShardManager` contains a `runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>`). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an `Arc<Mutex<Shard>>` too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple `shutdown` function on `Shard`, which is called directly by `ShardManager`.
mkrasnitski added a commit to mkrasnitski/serenity that referenced this pull request Oct 24, 2023
arqunis pushed a commit to arqunis/serenity that referenced this pull request Oct 24, 2023
Previous execution path of ShardManager::shutdown:

```
ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return
```

New execution path:

```
ShardManager::shutdown()
calls Shard::shutdown()
```

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a `shard: Arc<Mutex<Shard>>` field to `ShardRunnerInfo` (`ShardManager` contains a `runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>`). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an `Arc<Mutex<Shard>>` too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple `shutdown` function on `Shard`, which is called directly by `ShardManager`.
arqunis pushed a commit to arqunis/serenity that referenced this pull request Oct 24, 2023
arqunis pushed a commit to arqunis/serenity that referenced this pull request Oct 24, 2023
Previous execution path of ShardManager::shutdown:

```
ShardManager::shutdown()
sends ShardQueuerMessage::ShutdownShard to ShardQueuer::run()
calls ShardQueuer::shutdown()
sends ShardRunnerMessage::Shutdown to ShardRunner::recv()
calls ShardRunner::handle_rx_value()
calls ShardRunner::checked_shutdown()
calls ShardManager::shutdown_finished()
sends ACK to ShardManager::shutdown(), which can now finally return
```

New execution path:

```
ShardManager::shutdown()
calls Shard::shutdown()
```

To do that, ShardManager needed direct access to the Shard instance (instead of only sending messages to ShardRunner). So I added a `shard: Arc<Mutex<Shard>>` field to `ShardRunnerInfo` (`ShardManager` contains a `runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>`). This also meant ShardRunner couldn't own the Shard directly anymore but needed to store an `Arc<Mutex<Shard>>` too and lock it when needed. This makes for a bit of an ugly diff in shard_runner.rs but oh well.

After this, I removed shutdown related functions from ShardRunner and ShardQueuer (and the corresponding enum variants from ShardRunnerMessage and ShardQueuerMessage). Instead there's now just a single simple `shutdown` function on `Shard`, which is called directly by `ShardManager`.
arqunis pushed a commit to arqunis/serenity that referenced this pull request Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change The public API is changed, resulting in miscompilations or unexpected new behaviour for users examples Related to Serenity's examples. fix A solution to an existing bug. gateway Related to the `gateway` module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants