public-ip: ETIMEDOUT and ECONNRESET when running this action

It appears that there is some issue with this actions. The errors described below appears around 50% of the time.

Run haythem/public-ip@v1.3
  with:
    maxRetries: 5
Error: read ECONNRESET

and

Run haythem/public-ip@v1.3
  with:
    maxRetries: 5
Error: connect ETIMEDOUT 104.237.62.212:443

From the source code I can see that you fetch the IP from an external site. Maybe adding some backup sites to get the IP would be a better approach, since the error appears to be caused by that site?

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 18
  • Comments: 26 (3 by maintainers)

Commits related to this issue

Most upvoted comments

It has started to become a big blocker in some actions for me.

LIke @DamienDennehy I solved it by stopping using this and writing a simple curl command to get my IP from the URL of my choice. Based upon the GitHub documentation for Defining outputs for jobs

I can get an IP from any service, in this case canhazip.com and pass it as an output with the key ip to another step.

The ID of the step generating the IP address has a name of publicip and by echoing the result of the curl:

echo "ip='$response'" >> "$GITHUB_OUTPUT"

the IP address can be referenced in another step as steps.publicip.outputs.ip.

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    env:
      AWS_INSTANCE_SG_ID: sg-06d03c9f12345678
    steps:
      - name: Checkout
        uses: actions/checkout@v3.1.0

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v2
        with:
          role-to-assume: arn:aws:iam::123456789012:role/github-actions-role
          aws-region: ca-central-1

      - name: Get Public IP
        id: publicip
        run: |
          response=$(curl -s canhazip.com)
          echo "ip='$response'" >> "$GITHUB_OUTPUT"

      - name: Allowlist GH Actions runner IP address
        run: |
          aws ec2 authorize-security-group-ingress \
            --group-id $AWS_INSTANCE_SG_ID \
            --protocol tcp \
            --port 22 \
            --cidr ${{ steps.publicip.outputs.ip }}/32

Works very well.

Screenshot 2023-06-19 at 14 29 14

I too have had issues with this recently. I’ve created a workaround for Linux based runners using Cloudflare and a built in command using bash. Both are used here as a comparison.

    - name: Get Public IP (cloudflare-ip)
      id: cloudflare-ip
      run: | 
        ipv4=$(dig +short -4 txt ch whoami.cloudflare @1.0.0.1)
        echo "ipv4=$ipv4" >> $GITHUB_OUTPUT
      
    - name: Get Public IP (public-ip)
      id: public-ip
      uses: haythem/public-ip@v1.3

    - name: Log IP
      run: |
        echo IP Using haythem/public-ip: ${{ steps.public-ip.outputs.ipv4 }}
        echo IP Using cloudflare: ${{ steps.cloudflare-ip.outputs.ipv4 }}

In general both respond in a second or two, but today I saw this action take 1m20s to respond where Cloudflare responded in one second.

Hello everybody,

I’m sorry for the inconvenience. After investigating for some time, it appears that the ipify APIs is complaining about the request randomly. I’m trying to reach out to the owner of service. In the mean time, I’ll be building and hosting my own server for IP resolution.

I’ll keep you posted. Hang tight.

Hello everyone,

Sorry for the late response, I’ve been very busy lately with my daily job. I’ve already created the server and I’m trying to make some time to deploy it (probably this week-end).

Any news on this chaps? Is becoming quite the issue for us?

@lantrix This worked great for me. In my case I had to modify the job output to not wrap with single quotes.

- echo "ip='$response'" >> "$GITHUB_OUTPUT"
+ echo "ip=$response" >> "$GITHUB_OUTPUT"

@lantrix Thank you so much! This solved our issue as well.

Same issue happening to me about half of the time. I have not been able to recreate any failures manually by hitting https://api.ipify.org?format=json directly.