Code Monkey home page Code Monkey logo

Comments (4)

jnordberg avatar jnordberg commented on August 25, 2024

Looks like you're getting network errors, you need to handle them manually on the streams now (i might add something that handles stream errors in the future though).

You could do something like this (untested)

function run() {
  const stream = client.blockchain.createBlockStream()
  stream.on('data', (block) => { console.log('block', block) })
  stream.on('error', (error) => {
    console.log('stream error', error)
  })
  stream.on('end', () => {
    console.log('stream ended, recreating...')
    run()
  })
}

from dsteem.

therealwolf42 avatar therealwolf42 commented on August 25, 2024

Restarting works but it often happens that I'm looking for e.g. an upvote or comment and right when it should be found the connection interrupts. This makes it unreliable. Are you sure that there is no problem with the JSON return? Isn't there something to make it just skip that JSON? And if its possible to output which JSON actually caused the error?

Edit: I've added a bit of commenting to your dsteem code to see what is going on and it seems that instead of json - an html element get's parsed.

undefined:1
<html>
^

SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at IncomingMessage.stream.on (/Users/wolf/Bots/CommentVote/dsteem/lib/utils.js:132:81)
    at emitNone (events.js:110:20)
    at IncomingMessage.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1059:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

from dsteem.

therealwolf42 avatar therealwolf42 commented on August 25, 2024

After researching more I found out that this the error.

<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
</body>
</html>

Seems like you were right about network errors. But what is the best way to handle this? Because I'm looking for transactions and if transactions come in while I have that time-out error I'd lose transactions and that's very bad. I'd have to either start searching blocks from the moment it stopped or to watch for them in my transfer history (but is that even possible)?

Oh and by the way I'm using

const stream = client.blockchain.getOperationsStream({mode: dsteem.BlockchainMode.Irreversible});

and not 'createBlockStream' what you had in your example.

from dsteem.

jnordberg avatar jnordberg commented on August 25, 2024

@therealwolf42 try updating to 0.8.1, it should have you seeing much fewer network errors. The new default behaviour is to retry requests for 1 minute. If they timeout you still need to handle the error but should only happen if there's a major outage now

from dsteem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.