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

listTeamMemberships returns context cancelled #145

Open
milklineep opened this issue Jun 12, 2019 · 3 comments
Open

listTeamMemberships returns context cancelled #145

milklineep opened this issue Jun 12, 2019 · 3 comments
Labels

Comments

@milklineep
Copy link

I am trying to write a simple keybase bot. My intention was to auto-subscribe people to a rules channel as soon as they join. But I can't get the list of members. Here is my code:

const Bot = require('keybase-bot')
const bot = new Bot()
const username = 'username-redacted'
const paperkey = 'paperkey-redacted'
bot
  .init(username, paperkey, {verbose: false})
  .then(() => {
    console.log(`Your bot is initialized. It is logged in as ${bot.myInfo().username}`)
    bot.team
        .listTeamMemberships({team: 'team-name-redacted'})
        .then(res => console.log(res))
        .catch(error => {console.error(error)})
    bot.deinit()
  })
  .catch(error => {
    console.error(error)
    bot.deinit()
})

I get the following error when I run it:

Your bot is initialized. It is logged in as username-redacted
Error: API network error: doRetry failed, attempts: 3, timeout 5.324s, last err: context canceled (error 1601)
    at Team._runApiCommand (/home/epsilon/keybase-bot/node_modules/keybase-bot/index.js:565:13)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
    at async Team.listTeamMemberships (/home/epsilon/keybase-bot/node_modules/keybase-bot/index.js:1283:17)

I have copy-pasted the code from the example so I don't think the error comes from there. Keybase connects to the internet just fine. I don't know where the error comes from.

@pzduniak
Copy link
Member

Reproduced, thanks for your bug report!

@pzduniak
Copy link
Member

Looks like a bug in keybase/client, list-team-memberships fails straight after the service's startup. As a workaround either use .initFromRunningService(), wait a second or two before making the request or implement a retry mechanism:

const Bot = require('../../index.js')
const bot = new Bot()
const username = process.env.KB_USERNAME
const paperkey = process.env.KB_PAPERKEY

function timeout(time) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve()
    }, time)
  })
}

bot
  .init(username, paperkey, {verbose: false})
  .then(async () => {
    console.log(`Your bot is initialized. It is logged in as ${bot.myInfo().username}`)

    while (true) {
      try {
        const res = await bot.team.listTeamMemberships({team: process.env.KB_TEAM})
        console.log(res)
        break
      } catch (err) {
        console.log(err)
        await timeout(500)
      }
    }
  })
  .catch(error => {
    console.error(error)
    bot.deinit()
  })

@pzduniak pzduniak added the bug label Jun 13, 2019
@taruti
Copy link

taruti commented Nov 20, 2019

This seems to be working fine with the current master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants