go-textile icon indicating copy to clipboard operation
go-textile copied to clipboard

js-http-client invites.accept method threw 2 errors before accepting an invite

Open Schwartz10 opened this issue 6 years ago • 0 comments

Describe the bug I have a server running, recursively polling its peer's invite list. For any invites it finds, it accepts it right away.

After receiving an invite, the first attempt at accepting it resulted in the following error:

error accepting invite Error: Bad Request
    at handleErrors (/Users/jonathanschwartz/Documents/owl/website/streams-server/node_modules/@textile/js-http-client/dist/core/api.js:57:15)
    at Invites.<anonymous> (/Users/jonathanschwartz/Documents/owl/website/streams-server/node_modules/@textile/js-http-client/dist/core/api.js:110:20)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/jonathanschwartz/Documents/owl/website/streams-server/node_modules/@textile/js-http-client/dist/core/api.js:4:58)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

The second attempt to accept the invite:

error accepting invite Error: Conflict
    at handleErrors (/Users/jonathanschwartz/Documents/owl/website/streams-server/node_modules/@textile/js-http-client/dist/core/api.js:57:15)
    at Invites.<anonymous> (/Users/jonathanschwartz/Documents/owl/website/streams-server/node_modules/@textile/js-http-client/dist/core/api.js:110:20)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/jonathanschwartz/Documents/owl/website/streams-server/node_modules/@textile/js-http-client/dist/core/api.js:4:58)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

after the third attempt, it seemed that the invite was accepted because on the invitee's peer, there was a successful ANNOUNCE block that was added. However, the inviter's peer does not show any ANNOUNCE block (not sure if it is supposed to or not).

To Reproduce Steps to reproduce the behavior:

You could spin up a simple node program and run:

const textile = new Textile({
  url: 'http://127.0.0.1',
  // this port should be RECEIVING an invite
  port: 40600,
  config: {
    API: {
      HTTPHeaders: '*'
    }
  }
})

const listenAndAcceptInvites = () => {
  setTimeout(async () => {
    const { items } = await textile.invites.list()
    try {
      await Promise.all(
        items.map(async invite => textile.invites.accept(invite.id))
      )
    } catch (error) {
      throw new Error('error accepting invite', error)
    }
    listenAndAcceptInvites()
  }, 5000)
}

listenAndAcceptInvites()

then using the CLI, send an invite to this peer (http://127.0.0.1:40600)

Expected behavior I would expect the first call to textile.invites.accept(id) to not throw an error. I might also expect the ANNOUNCE block to be seen on the inviter peer's daemon (but not sure if that's not done by design)

Additional context Add any other context about the problem here.

I'm running

"@textile/js-http-client": "^0.2.15",
node v11.9.0
go-textile version: v0.1.12
Repo version: 13
System version: amd64/darwin
Golang version: go1.12.3

possible this is related to https://github.com/textileio/go-textile/issues/745

Schwartz10 avatar May 08 '19 02:05 Schwartz10