Skip to content

Commit

Permalink
feat: SaveBotChat() does not take Context anymore
Browse files Browse the repository at this point in the history
It is dangerous to allow user to pass context to this func as if it's a transactional context it might lead to deadlock
  • Loading branch information
trakhimenok committed Sep 14, 2024
1 parent ff89c62 commit ac8a07e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion botsfw/context_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func SetAccessGranted(whc WebhookContext, value bool) (err error) {
chatDataBase := chatData.Base()
chatDataBase.DtUpdated = now
chatDataBase.SetDtLastInteraction(now) // Must set DtLastInteraction through wrapper
if err = whc.SaveBotChat(c); err != nil {
if err = whc.SaveBotChat(); err != nil {
err = fmt.Errorf("failed to save bot botChat entity to db: %w", err)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion botsfw/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (whRouter *WebhooksRouter) Dispatch(webhookHandler WebhookHandler, responde
if chatData.IsChanged() {
chatData.SetUpdatedTime(now)
}
if err = whc.SaveBotChat(c); err != nil {
if err = whc.SaveBotChat(); err != nil {
log.Errorf(c, "Failed to save botChat data: %v", err)
if _, sendErr := whc.Responder().SendMessage(c, whc.NewMessage("Failed to save botChat data: "+err.Error()), BotAPISendMessageOverHTTPS); sendErr != nil {
log.Errorf(c, "Failed to send error message to user: %v", sendErr)
Expand Down
5 changes: 3 additions & 2 deletions botsfw/webhook_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ type WebhookContext interface { // TODO: Make interface much smaller?

//Store() botsfwdal.DataAccess

// SaveBotChat takes context as we might want to add timeout or cancellation or something else.
SaveBotChat(ctx context.Context) error
// SaveBotChat // It is dangerous to allow user to pass context to this func as if it's a transactional context it might lead to deadlock
// Previously: takes context as we might want to add timeout or cancellation or something else.
SaveBotChat() error

//RecordsMaker() botsfwmodels.BotRecordsMaker

Expand Down

0 comments on commit ac8a07e

Please sign in to comment.