question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

INSERT randomly don't return.

See original GitHub issue

I have a cron job running every 10 secondes and in it a loop that insert data if there was new data added on blockchain data storage, in short a cron caching Blockchain data into local pg db.

For some reasons, randomly (or at least it feel random), i sometimes get the insert not returning anything and then stay stuck there:

  for (var tx in addToUnconfirmed) {
    console.log("try me")
    try {
      console.log("inside try")
      let insertUnconfirmed = await pool.query(`INSERT INTO unconfirmed ("txid", "height", "function", "address", "update_id") VALUES ($1, $2, $3, $4, $5)`,
      [
        addToUnconfirmed[tx].txid, // current calling tx id
        addToUnconfirmed[tx].height, // height of the tx
        addToUnconfirmed[tx].function, // called function
        addToUnconfirmed[tx].address, // sender address
        addToUnconfirmed[tx].update_id, // for artwork
      ]);
      logger.info("Added txid " + addToUnconfirmed[tx].txid + " with height " + addToUnconfirmed[tx].height + " and function " + addToUnconfirmed[tx].function + " to unconfirmed pool");

    } catch (err) {
      isProcessing = false;
      logger.info(err);
    }
  }

addToUnconfirmed is simply an array with details of a (or multiple) new transaction(s) to insert, it can work 10 call in a row and at 11 just freeze at “inside try” then i manually restart it and all work again, untill next random “no return”.

My connection is as follow:

const pool = new Pool({
  user: process.env.user,
  password: process.env.password,
  host: process.env.host,
  port: "25060",
  database: process.env.database,
  ssl: {
    rejectUnauthorized: false,
    ca: fs.readFileSync('ca-certificate.crt').toString()
  }
});

Any idea what could be the problem? i Have this locally and on remote server, using node-postgres 8.3.3, nodejs 12.15.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
christopheSeekacommented, Sep 29, 2020

Im using node-cron, was able to sort it out, i switched from pool to client as you recommanded since i do all sequentially. But i never close with client.end()… else it doesn’t work on next cron call. Will study the doc a bit more and try find better way. Thanks a lot for the help, appreciate it 😃

0reactions
boromispcommented, Sep 29, 2020

What are you using for scheduling the cron job? You might want to try to ensure that only one instance of the script is running at once.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I let a function randomly return either a true or a false ...
You need some kind of random information, and based on its value, you can return true in half of its possible cases, and...
Read more >
Insert, move, or delete page breaks in a worksheet
To return to Normal view after you finish working with the page breaks, on the View tab, in the Workbook Views group, click...
Read more >
Generate Random Numbers | Excel VBA Tutorial
This function stands for random and when you use this function in code it returns a random number between 0 to 1. In...
Read more >
How to Generate Random Numbers in Excel
In the active cell, enter =RANDBETWEEN(1,100). Hold the Control key and Press Enter. This will instantly give me 10 random numbers in the...
Read more >
Day 79 — Insert, Delete, Random O(1) | by House of Codes
getRandom : Returns a random element from current set of elements. ... Don't forget to hit the follow button✓to receive updates when we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found