Skip to content

getaddrinfo ENOTFOUND api.sandbox.braintreegateway.com - after idle time. #229

@shreyas14oct

Description

@shreyas14oct

Okay, here is the following code snippet i am using (in Nodejs envoirment) on debian:

const gateway = new braintree.BraintreeGateway({
environment: braintree.Environment.Sandbox,
merchantId: process.env.BRAINTREE_MERCHANTID,
publicKey: process.env.BRAINTREE_PUBLICKEY,
privateKey: process.env.BRAINTREE_PRIVATEKEY
});

app.get("/find-customer", (req, res) => {
console.log("Function: find-customer");
const start = process.hrtime.bigint(); // Start timer
console.log("/find-customer", req.query.customerId);

if (req.query.customerId) {
    gateway.customer.find(req.query.customerId, function (err, customer) {
        console.log(err, "/found-customer", customer?.id);
        if (err) {
            res.json({
                status: "error",
                errors: err
            }).end();
        } else {
            res.json({
                status: "success",
                customer: customer
            }).end();
        }
        const end = process.hrtime.bigint(); // End timer
        console.log(`Processing time: ${(end - start) / BigInt(1000000)} ms`);
    });
} else {
    res.json({
        status: "error",
        errors: "Invalid Request"
    }).end();
    const end = process.hrtime.bigint(); // End timer
    console.log(`Processing time: ${(end - start) / BigInt(1000000)} ms`);
}

});

after some idle time , iam getting below error:

so i am getting below error:

Processing time: 1546 ms
/find-customer 91536922090
Error [unexpectedError]: Unexpected request error: Error: getaddrinfo ENOTFOUND api.sandbox.braintreegateway.com
at Object.UnexpectedError (/var/www/clients/client1/web1/web/node-service/node_modules/braintree/lib/braintree/exceptions.js:7:15)
at ClientRequest. (/var/www/clients/client1/web1/web/node-service/node_modules/braintree/lib/braintree/http.js:202:32)
at ClientRequest.emit (node:events:514:28)
at TLSSocket.socketErrorListener (node:_http_client:501:9)
at TLSSocket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'unexpectedError'
} /found-customer undefined
Processing time: 3228 ms

but after repeated calls it succeeds.

some investigation as follows:

user@server1:~$ nslookup api.sandbox.braintreegateway.com
;; Got SERVFAIL reply from 127.0.0.1, trying next server
Server: ::1
Address: ::1#53

** server can't find api.sandbox.braintreegateway.com: SERVFAIL

user@server1:~$ dig api.sandbox.braintreegateway.com

; <<>> DiG 9.16.50-Debian <<>> api.sandbox.braintreegateway.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 29347
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: c03e9bf9857b9a6f0100000067fe003f1ae4cf60a5c4f564 (good)
;; QUESTION SECTION:
;api.sandbox.braintreegateway.com. IN A

;; Query time: 3200 msec
;; SERVER: ::1#53(::1)
;; WHEN: Tue Apr 15 12:14:15 IST 2025
;; MSG SIZE rcvd: 89

and the consecutive hit got:

user@server1:~$ dig api.sandbox.braintreegateway.com

; <<>> DiG 9.18.30-0ubuntu0.22.04.2-Ubuntu <<>> api.sandbox.braintreegateway.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53921
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 18b50a8aeaf4ad0101000000680dac3197be9f982943a37d (good)
;; QUESTION SECTION:
;api.sandbox.braintreegateway.com. IN A

;; ANSWER SECTION:
api.sandbox.braintreegateway.com. 60 IN CNAME gateway-api.sandbox.braintreegateway.com.
gateway-api.sandbox.braintreegateway.com. 60 IN CNAME cdn-a.sandbox.braintree-api.com.
cdn-a.sandbox.braintree-api.com. 300 IN A 159.242.242.129
cdn-a.sandbox.braintree-api.com. 300 IN A 159.242.242.128

;; Query time: 90 msec
;; SERVER: 127.0.0.1#53(127.0.0.1) (UDP)
;; WHEN: Sat Apr 26 21:01:53 PDT 2025
;; MSG SIZE rcvd: 192

Please help me to figure out issue here and resolve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions