deno icon indicating copy to clipboard operation
deno copied to clipboard

bug: Connection refused (os error 111)

Open alexanderGalushka opened this issue 4 years ago • 14 comments

I run deno in the docker container in the k8s pod for as a REST API service. Every N seconds this deno service sends a POST request with metrics data over to another service in k8s, prometheus pushgateway

here is the code snippet of how the POST request is being made with fetch:

// function to push metrics to prometheus "pushgateway"
export async function pushMetrics(
  id: string,
  metrics: string,
) {
  const pgURL = getPushgatewayHostName(pushgatewayJobName, id);
  try {
    const cleanedUpFileContent = unescape(encodeURIComponent(metrics));
    const out = new TextEncoder().encode(cleanedUpFileContent);  
    const response = await fetch(
      pgURL,
      {
        method: "POST",
        body: out,
      },
    );
    if (response.status != 202 && response.status != 200) {
      log.error(`failed to POST to pushgateway URL ${pgURL}, status ${response.status}`);
    }
  } catch (e) {
    log.error(`unexpected error: failed to POST to pushgateway URL ${pgURL}, ${e}`);
  }
}

function getPushgatewayHostName(pushgatewayJobName: string, id: string): string {
  const pushgatewayURI = `metrics/job/${pushgatewayJobName}/instance/${id}`;
  if (ENV == undefined || ENV == "") {
    return `http://pushgateway:9091/${pushgatewayURI}`;
  }
  return `http://${ENV}-${basePushgatewayK8sServiceHost}/${pushgatewayURI}`; 
}

permissions for the network calls are wide open:

CMD ["deno", "run", "--cached-only", "--unstable", **"--allow-net"**, "--allow-read=./workers", "--allow-env", "--v8-flags=--disallow-code-generation-from-strings", "main.ts"]

request comes through OK if I run it outside of k8s (not using k8s dns service host name e.g. pgURL=http://pushgateway.mynamespace.svc.cluster.local:9091): bring up 2 docker containers attached to the same network, so the deno service POST to http://pushgateway:9091, pushgateway is the name of the second container deno service is POSTing to

if I run it in the k8s I get the following error:

unexpected error: failed to POST to pushgateway URL http://myenv-pushgateway.mynamespace.svc.cluster.local:9091/metrics/job/myjob/instance/1234567890, Http: error sending request to url (http://myenv-pushgateway.mynamespace.svc.cluster.local:9091/metrics/job/myjob/instance/1234567890): error trying to connect: tcp connect error: Connection refused (os error 111)

looks like a Rust error message:

error trying to connect: tcp connect error: Connection refused (os error 111)

I can exec into the deno container in k8s and curl pushgateway, so it's not related to k8s network policies

not sure if these 2 issues are related: https://github.com/denoland/deno/issues/7660 https://github.com/denoland/deno/issues/6751

using:

  • latest deno v1.4.2
  • k8s cluster v1.18.6

@bartlomieju @kitsonk @hayd can you please take a look

alexanderGalushka avatar Sep 25 '20 23:09 alexanderGalushka

You don't need to @ people to have a potential issue looked at.

kitsonk avatar Sep 26 '20 00:09 kitsonk

This certainly reads like #6751.

hayd avatar Sep 26 '20 05:09 hayd

You don't need to @ people to have a potential issue looked at.

true

alexanderGalushka avatar Oct 01 '20 22:10 alexanderGalushka

has anyone looked at this?

alexanderGalushka avatar Oct 13 '20 18:10 alexanderGalushka

bump +1

puneetk avatar Oct 13 '20 18:10 puneetk

Same thing appeared again on my setup. Suddenly with the recent update of the docker image (denoland/latest) Iam not able to connect to my mariadb nodes anymore. If lucky I get the os error 111, if not the entire thread just get hung.

Also reproductable with the smalest possible mysql connection sample excluding all higher level libs.

Merulast avatar Nov 02 '22 17:11 Merulast

Same here @Merulast 😞

We're also having issues with our application on production connecting to our supabase postgres db. No issues when running the application locally or when connecting to the database directly.

itsahsiao avatar Nov 03 '22 18:11 itsahsiao

@littledivy please take a look

bartlomieju avatar Nov 03 '22 18:11 bartlomieju

We resolved it by updating our deno postgres driver to the latest version. We were on [email protected] and changing to [email protected] seemed to fix it for some reason.

itsahsiao avatar Nov 03 '22 19:11 itsahsiao

I’m having the same issue. I can’t connect to the local postgres database (using supabase).

hamanuha avatar Jan 11 '23 22:01 hamanuha

I’m having the same issue. I can’t connect to the local postgres database (using supabase).

It works when using 172.17.0.1 instead of localhost

hamanuha avatar Jan 12 '23 10:01 hamanuha

I have the same issue. Thanks for sharing @hamanuha , replacing localhost by 172.17.0.1 works for me as well.

cohlar avatar Jan 25 '23 10:01 cohlar

I’m having the same issue. I can’t connect to the local postgres database (using supabase).

It works when using 172.17.0.1 instead of localhost

I had the same issue connecting from deno to mongodb over docker. This solved my issue. Thank you so much for shareing!

Peter-Kang avatar Apr 27 '23 03:04 Peter-Kang

I’m having the same issue. I can’t connect to the local postgres database (using supabase).

It works when using 172.17.0.1 instead of localhost

Wow this just worked!

I am using supabase and deno edge function. Could you explain how this works?

topperspal avatar Dec 19 '23 16:12 topperspal

it's Docker's gateway for its bridge network.

try running command in your terminal docker network inspect bridge

image

anil-zenollect avatar Jul 01 '24 06:07 anil-zenollect