nodejs and express with connectiontimeout(H13) in Heroku

Asked

Viewed 144 times

1

Hello, I have an api in Heroku and There communicates with the pagseguro api(notifications), the wheel that handles the notification needs to take the transaction code that is received per post, make a query in the pagseguro api to get the status and some more data, After that you need to access my bank to consult some tables and update others (add coins to the user and register in the stream) the problem I am finding is H13 (conection timeout). when I put the code on another server the error remains my route:

router.post("/notificacao", function (req, res) {
    const parseString = require('xml2js').parseString;
    const request = require("request");
    if (req.body.notificationType == "transaction") {
        console.log("reconheceu o type")
        if (req.body.notificationCode) {
            const link = "https://ws.pagseguro.uol.com.br/v3/transactions/notifications/"
                + req.body.notificationCode
                + "?email=****&token=****";
            console.log(link);
            request.get(link, (error, response, body) => {
                if (error) {
                    res.status(503).send({ status: "erro" })
                    return console.dir(error);
                }
                // return
                parseString(body, function (err, result) {
                    const status = result.transaction.status
                    Transacao.select(null, [{ name: "cod_transacao", value: result.transaction.code }])
                        .then((rowsT, fieldsR) => {
                            rowsT = rowsT[0]
                            console.log("rowsT", rowsT)
                            const notData = {
                                cod_transacao: result.transaction.code,
                                cod_mod: req.body.notificationCode,
                                status: result.transaction.status,
                                data_modificacao: fecha.format(new Date(), 'YYYY-MM-DD HH:mm:ss'),
                            }
                            // console.log("o q eu consultei", rowsT[0].instalador_id)
                            if ((parseInt(status) == 3 || parseInt(status) == 4) && rowsT.moedas != "adicionadas") {
                                console.log("add moedas")
                                const Instalador = require("../../instalador/instalador.js")
                                Instalador.addMoedas(rowsT.instalador_id, rowsT.id_plano).then(() => {
                                    notData['moedas'] = 'adicionadas'
                                    Transacao.update(notData).then((rows, fields) => {
                                        res.status(200).send(rows)
                                    })
                                })
                            } else {
                                if (parseInt(status) > 5) {
                                    if (rowsT.moedas = 'adicionadas') {
                                        const Instalador = require("../../instalador/instalador.js")
                                        Instalador.removeMoedas(rowsT.instalador_id, rowsT.id_plano).then(() => {
                                            notData['moedas'] = 'removidas'
                                            Transacao.update(notData).then((rows, fields) => {
                                                res.status(200).send(rows)
                                            })
                                        })
                                    } else {
                                        Transacao.update(notData).then((rows, fields) => {
                                            res.status(200).send(rows)
                                        })
                                    }
                                }

                            }


                        }).catch((error => {
                            res.status(500).send({
                                erro: String(err)
                            })
                        }))
                });
            });
        }
    }
    console.log(req.body)
})

the error message is:

Dec 26 02:56:07 api-webar-teste heroku/router:  at=error code=H13 desc="Connection closed without response" method=POST path="/financeiro/transacao/notificacao" host=****.herokuapp.com request_id=940e82ff-ae69-41c6-8c4e-da22cea9f5eb fwd="186.234.144.18" dyno=web.1 connect=1ms service=26003ms status=503 bytes=0 protocol=https  

1 answer

0


I changed my bank connection to a pool as in Docs

var mysql = require('mysql');
var pool  = mysql.createPool({
  connectionLimit : 10,
  host            : 'example.org',
  user            : 'bob',
  password        : 'secret',
  database        : 'my_db'
});
 
pool.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].solution);
});

that solved the timeouts

Browser other questions tagged

You are not signed in. Login or sign up in order to post.