Skip to content

Conversation

@odourain
Copy link

@odourain odourain commented Oct 25, 2023

Problem

Before starting the bot I do a setCommands and its goroutine [which reads channel variable] does not have time to complete before the start method [which writes to channel variable].

Previous read at 0x00c0015a6628 by goroutine 106:
https://github.com/tucnak/telebot/blob/v3/api.go#L39

Write at 0x00c0015a6628 by main goroutine:
https://github.com/tucnak/telebot/blob/v3/bot.go#L205

Decision

Use mutex for use channel stopClient.

Also added changes from https://github.com/caalberts/telebot to work with testnet.

@demget demget changed the title 🔧 Fix race stop client channel api: fix race for a stopClient channel Nov 18, 2023
Copy link
Contributor

@davseby davseby left a comment

Choose a reason for hiding this comment

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

Before I noticed this PR, I did a fix of my own. I leave it up for the maintainers to decide which one to use, however I did notice some issues with this one 🤷🏿.

#641


// do nothing if called twice
if b.stopClient != nil {
if b.getChanStopClient() != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

We're still racing here, it would be better to encapsulate nil checking and creating into a one mutex call. Same with the stop.

@demget demget closed this Feb 20, 2024
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.

4 participants