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

[Bug]: It is possible for DiscordService to accidentally try to start the Dispatch service multiple times (despite that it's already running). #231

Closed
AraHaan opened this issue Sep 1, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@AraHaan
Copy link
Contributor

AraHaan commented Sep 1, 2022

Description

Currently it looks like DiscordService does not check to see if the Dispatch service is already running before it tries to start it (again).

This happened when I got Foxtrek64/Remora.Plugins#1 and LuzFaltex/LuzFaltex.Extensions.DependencyInjection#1 to work (experimental Rewrite to Remora.Plugins to allow for unloadable plugins that also automatically reloads them when it sees that a plugin assembly was recompiled (updated)).

I suspect it might be because it's trying to initialize DiscordService each time a plugin's ServiceCollection is added to the MutableServiceProvider I made (which allows adding / removing services that are from plugins). It might be worth while to patch DiscordService so things like this would just work:tm:.

Steps to Reproduce

  • Clone these 2 pull requests (the ones posted above)
  • dotnet pack -c Release and then add their ./nuget/ folder's to a nuget.config file to a Discord Bot that uses Remora.Plugins
  • that add this to your IHostBuilder config to your bot (Extensions.Hosting):
    • .UseServiceProviderFactory(new MutableServiceProviderFactory()) (Add using LuzFaltex.Extensions.DependencyInjection; to top of file first).
  • try to run the bot in debug (or in a way that allows you to see the logs).

Expected Behavior

For everything to just work:tm:.

Current Behavior

DiscordService errors, which then kills the bot.

Library / Runtime Information

Version of Remora.Discord: 2022.47.0
Version of .NET Runtime: 6.0.8 (servicing)

Logs

2022-09-01 09:01:55.571 -04:00 [INF] [Remora.Discord.Gateway.DiscordGatewayClient] Starting dispatch service...
2022-09-01 09:01:55.583 -04:00 [INF] [Remora.Discord.Gateway.DiscordGatewayClient] Retrieving gateway endpoint...
2022-09-01 09:01:55.595 -04:00 [INF] [Remora.Discord.Gateway.DiscordGatewayClient] Starting dispatch service...
2022-09-01 09:01:55.603 -04:00 [ERR] [Remora.Discord.Hosting.Services.DiscordService] Exception during gateway connection: The dispatch service is already running.
System.InvalidOperationException: The dispatch service is already running.
   at Remora.Discord.Gateway.Services.ResponderDispatchService.Start()
   at Remora.Discord.Gateway.DiscordGatewayClient.RunAsync(CancellationToken stopRequested)
2022-09-01 09:01:55.712 -04:00 [INF] [Remora.Discord.Gateway.DiscordGatewayClient] Starting a new session (999 session starts remaining of 1000; limits reset in "23:30:50.8660000")
2022-09-01 09:01:55.923 -04:00 [INF] [Remora.Discord.Gateway.DiscordGatewayClient] Connecting to the gateway...
2022-09-01 09:01:55.923 -04:00 [INF] [Remora.Discord.Gateway.DiscordGatewayClient] Starting dispatch service...
2022-09-01 09:01:55.924 -04:00 [ERR] [Remora.Discord.Hosting.Services.DiscordService] Exception during gateway connection: The dispatch service is already running.
System.InvalidOperationException: The dispatch service is already running.
   at Remora.Discord.Gateway.Services.ResponderDispatchService.Start()
   at Remora.Discord.Gateway.DiscordGatewayClient.RunAsync(CancellationToken stopRequested)
2022-09-01 09:01:55.924 -04:00 [INF] [Remora.Discord.Gateway.DiscordGatewayClient] Starting dispatch service...
2022-09-01 09:01:55.924 -04:00 [ERR] [Remora.Discord.Hosting.Services.DiscordService] Exception during gateway connection: The dispatch service is already running.
System.InvalidOperationException: The dispatch service is already running.
   at Remora.Discord.Gateway.Services.ResponderDispatchService.Start()
   at Remora.Discord.Gateway.DiscordGatewayClient.RunAsync(CancellationToken stopRequested)
2022-09-01 09:01:55.924 -04:00 [INF] [Remora.Discord.Gateway.DiscordGatewayClient] Starting dispatch service...
2022-09-01 09:01:55.925 -04:00 [ERR] [Remora.Discord.Hosting.Services.DiscordService] Exception during gateway connection: The dispatch service is already running.
System.InvalidOperationException: The dispatch service is already running.
   at Remora.Discord.Gateway.Services.ResponderDispatchService.Start()
   at Remora.Discord.Gateway.DiscordGatewayClient.RunAsync(CancellationToken stopRequested)
@AraHaan AraHaan added the bug Something isn't working label Sep 1, 2022
@AraHaan
Copy link
Contributor Author

AraHaan commented Sep 1, 2022

Ah I see now, it was fixed with 8b8b64f, however no nuget stable release was pushed yet so I will need to use the unstable packages temporarily until then.

@AraHaan AraHaan closed this as completed Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant