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

Hubのpayloadの型キャストで起こっていたPanicを修正 #2095

Merged
merged 2 commits into from
Nov 20, 2023

Conversation

logica0419
Copy link
Member

@logica0419 logica0419 commented Nov 20, 2023

グループ追加 / グループ削除で、Hubのpayloadの型キャストが適切に行われておらず、Bot ServiceインスタンスがPanicを起こしてtraQが落ちるというバグが確認された
そのため、以下の二つのPanicを直した

Created

参考:

repo.hub.Publish(hub.Message{
Name: event.UserGroupCreated,
Fields: hub.Fields{
"group_id": g.ID,
"group": g,
},
})

panic: interface conversion: interface {} is *model.UserGroup, not model.UserGroup

goroutine 1811903 [running]:
github.com/traPtitech/traQ/service/bot/handler.UserGroupCreated({0x1e99010, 0xc000092090}, {0x1c17bf5?, 0x12?, 0x2d6dae0?}, {0x50?, 0x1ad6280?}, 0x4e3bc0?)
        /go/src/github.com/traPtitech/traQ/service/bot/handler/ev_user_group_created.go:15 +0x36e
github.com/traPtitech/traQ/service/bot.(*serviceImpl).start.func1.1({{0x1c17bf5, 0x12}, {0x0, 0x0, 0x0}, 0xc000400d80})
        /go/src/github.com/traPtitech/traQ/service/bot/service_impl.go:72 +0x10b
created by github.com/traPtitech/traQ/service/bot.(*serviceImpl).start.func1 in goroutine 43
        /go/src/github.com/traPtitech/traQ/service/bot/service_impl.go:68 +0xc7

Deleted

参考:

repo.hub.Publish(hub.Message{
Name: event.UserGroupDeleted,
Fields: hub.Fields{
"group_id": id,
},
})

panic: interface conversion: interface {} is nil, not model.UserGroup

goroutine 123999 [running]:
github.com/traPtitech/traQ/service/bot/handler.UserGroupDeleted({0x1e99010, 0xc000404090}, {0x1c17c19?, 0x12?, 0x2d6dae0?}, {0xc000b40ef0?, 0x415f50?}, 0x7fcf69ff15b8?)
        /go/src/github.com/traPtitech/traQ/service/bot/handler/ev_user_group_deleted.go:15 +0x2c5
github.com/traPtitech/traQ/service/bot.(*serviceImpl).start.func1.1({{0x1c17c19, 0x12}, {0x0, 0x0, 0x0}, 0xc001328ff0})
        /go/src/github.com/traPtitech/traQ/service/bot/service_impl.go:72 +0x10b
created by github.com/traPtitech/traQ/service/bot.(*serviceImpl).start.func1 in goroutine 42
        /go/src/github.com/traPtitech/traQ/service/bot/service_impl.go:68 +0xc7

Copy link
Member

@motoki317 motoki317 left a comment

Choose a reason for hiding this comment

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

他のところはあまり網羅的には見てないけどokしておきます

@motoki317
Copy link
Member

typesafeなpubsubは、TypeScriptみたいに型自体をindexed accessできないから、https://github.com/traPtitech/NeoShowcase/blob/b7902613441584ef24024dd8ec9f047b4621ab8b/pkg/domain/pubsub.go のようなものをイベントごとにstructのフィールドで持つ、くらいしか考えられないな

@logica0419
Copy link
Member Author

わかる、それが欲しい

Copy link
Member

@H1rono H1rono left a comment

Choose a reason for hiding this comment

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

良さそう、 #1894 でバグに気づけなくて申し訳ないです
念の為確認なんですが、↓はWebSocketで配信するイベントなので関係ない、という認識であってますか?あってたらmergeお願いします

func userGroupCreatedHandler(ns *Service, ev hub.Message) {
broadcast(ns,
"USER_GROUP_CREATED",
map[string]interface{}{
"id": ev.Fields["group_id"].(uuid.UUID),
},
)
}

func userGroupDeletedHandler(ns *Service, ev hub.Message) {
broadcast(ns,
"USER_GROUP_DELETED",
map[string]interface{}{
"id": ev.Fields["group_id"].(uuid.UUID),
},
)
}

@logica0419
Copy link
Member Author

そうですね、前回バグが入った範囲ではないので、変更しないで大丈夫という認識です
実際こっちはフィールド名と型が一致してるので問題ないはずです

@logica0419 logica0419 merged commit acfda5c into master Nov 20, 2023
3 of 4 checks passed
@logica0419 logica0419 deleted the fix/hub-payload-panic branch November 20, 2023 12:29
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.

None yet

3 participants