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

Example Request: Sharding #70

Open
bkuhl opened this issue Mar 2, 2024 · 4 comments
Open

Example Request: Sharding #70

bkuhl opened this issue Mar 2, 2024 · 4 comments
Labels
bug Something isn't working shard

Comments

@bkuhl
Copy link

bkuhl commented Mar 2, 2024

I'm on an ARM OSx device.

I'm not very familiar with golang and am trying to migrate my Discord bot to use your library. It's a sharded bot. I'm following the docs here and am encountering an error I don't understand. I was wondering if you'd be able to add a full example of how to run a sharded bot as I seem to be doing something wrong.

	bot := &disgo.Client{
		Authentication: disgo.BotToken(token),
		Config: &disgo.Config{
			Gateway: disgo.Gateway{
				GatewayPresenceUpdate: &disgo.GatewayPresenceUpdate{
					Status: status,
				},
			},
		},
	}

	bot.Config.Gateway.ShardManager = new(shard.InstanceShardManager)
	s := bot.Config.Gateway.ShardManager

	s.Connect(bot)

I keep getting

bot-1  | panic: runtime error: invalid memory address or nil pointer dereference
bot-1  | [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x3b5360]
bot-1  | 
bot-1  | goroutine 1 [running]:
bot-1  | github.com/switchupcb/disgo/shard.(*InstanceShardManager).Connect(0x400010e580, 0x400010e500)
bot-1  |        /go/pkg/mod/github.com/switchupcb/disgo/[email protected]/instance.go:86 +0x30
bot-1  | main.main()
bot-1  |        /app/main.go:64 +0x354
bot-1  | exit status 2
@imide
Copy link

imide commented Mar 31, 2024

unfortunately, i dont think this project is being maintained anymore... this looks really nice to use (and i find dgo really annoying to use so)
i would help but im also brand new, a fucking moron, and idk where to start lol.
😭

@bkuhl
Copy link
Author

bkuhl commented Apr 1, 2024

We switched to use https://github.com/bwmarrin/discordgo and github.com/servusdei2018/shards for sharding and it's working great.

@bkuhl bkuhl closed this as completed Apr 1, 2024
@switchupcb
Copy link
Owner

unfortunately, i dont think this project is being maintained anymore...
@imide

I was homeless.

if you'd be able to add a full example of how to run a sharded bot as I seem to be doing something wrong.
@bkuhl

The short term fix is to use `bot.Config.Gateway.ShardManager.SetNumShards(2)'.

The long term fix is that the Limit struct should not be nil.

I can implement this fix when I want or when I am paid to do so. However, you are using discordgo, so no payment is expected.

Here is what caused the issue.

Line 86 is a reference to totalShards = sm.Limit.RecommendedShards

The instantiated shard manager has a nil Limit struct.

When you call Connect, totalShards is not set, so it attempts to read from a nil pointer.

The shard test doesn't catch this issue because it calls bot.Config.Gateway.ShardManager.SetNumShards(2) which sets totalShards to 2.

The short term fix is to use that line of code and set the shards to a given number.

The long term fix is to make sure there is a limit set and consider whatever reason I had for not doing so.

https://github.com/servusdei2018/shards

Does this package make you use a lot of for loops to call code on each shard?

@switchupcb switchupcb reopened this Jul 9, 2024
@switchupcb switchupcb added bug Something isn't working shard labels Jul 9, 2024
@imide
Copy link

imide commented Jul 10, 2024

I was homeless.

oh no! i hope you're back on your feet 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working shard
Projects
None yet
Development

No branches or pull requests

3 participants