ssh-action: I/O Timeout Error

It doesn’t just make any other error:

`======CMD====== docker rm -f $(docker ps -aq -f name=erp-front) docker rmi $(docker images | grep ‘emiryumak/erp-front’ | awk ‘{print $3}’) docker pull emiryumak/erp-front:latest docker run --name erp-front -p 5000:80 --restart=always -d emiryumak/erp-front

======END====== ======ENV======

======END====== 2020/05/16 20:31:15 dial tcp :: i/o timeout`

I don’t understand thats error. Its meaning can not connect to my server?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I faced the same issue as well (while having none with appleboy/scp-action) and was eventually able to resolve this by reconfiguring ufw on my server. The action for 22/tcp was LIMIT for some reason.

Running

sudo ufw allow ssh

fixed it for me.

In my case, it was a conflict because I was declaring to use it for the Node app, while this was affecting the ssh-action.

env:
  PORT: 8000

The solution was to rename the variable from PORT to APP_PORT.

I just started getting this issue as well. The commands I was executing on the remote server was a series of docker commands as part of my deployment process. I connected to the server and ran them manually and they ran fine.

@luisfalconmx’s comment stood out to me since I was also running docker commands. I connected to a box and ran docker image prune -a -f it took a minute but then completed, clearing up 8GB of space on the machine. After that the deployment actions using SSH completed successfully.

I suspect the machine may have slowed down due to all the images on disk. I’m going to try incorporating docker image prune -a -f into my deployment process and see if it helps with future deployments. Certainly all that space consumption will eventually strangle the server anyway.

The Problem

After several hours trying to solve this problem, I came to the next conclusion:

Apparently there are some commands like docker rm -f $(docker ps -aq -f name=erp-front) or docker rmi $(docker images | grep 'emiryumak/erp-front' | awk '{print $3}') that make the connection saturate and throw the I/O Timeout error.

This may be because the command docker rmi $(docker images | grep 'emiryumak/erp-front' | awk '{print $3}') first tries to return all images named emiryumak/erp-front and then remove each of them, which can be too complicated to process.

Possible Solution

My recommendation would be to keep the commands as simple as possible or use them as shown in official documentation. Also make sure you configure the credentials correctly. In case you use an ssh key make sure to add the public key on the server and the private key in the repository as a secret.

Setting up a SSH Key

Some examples of how to use the commands correctly.

Delete a specific container

# ❌ do not this
docker rm -f $(docker ps -aq -f name=erp-front)
# ✅ do this
docker rm my_super_app -f

# or this
docker run --name my_super_app -d --rm -p 80:80 octocat/myimage:latest
docker stop my_super_app

Delete old and unused images

# ❌ do not this
docker rmi $(docker images | grep 'emiryumak/erp-front' | awk '{print $3}')
# ✅ do this
docker image prune -a -f

Workflow File

This is the configuration that I am using to run a docker container on a server via ssh every time I publish a new release

name: CD
on:
  release:
    types: [published]
jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to server
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USER }}
          key: ${{ secrets.SSH_KEY }}
          port: ${{ secrets.SSH_PORT }}
          script: |
            docker system prune -a -f
            docker stop my_super_app
            docker run --name my_super_app -d --rm -p 80:80 octocat/myimage:latest

With environment variables

name: CD
on:
  release:
    types: [published]
jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    steps:
      - name: Get repository metadata
        uses: varunsridharan/action-repository-meta@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Deploy to server
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USER }}
          key: ${{ secrets.SSH_KEY }}
          port: ${{ secrets.SSH_PORT }}
          script: |
            docker system prune -a -f
            docker stop ${{ env.REPOSITORY_OWNER }}_${{ env.REPOSITORY_SLUG }}
            docker run --name ${{ env.REPOSITORY_OWNER }}_${{ env.REPOSITORY_SLUG }} -d --rm -p ${{ secrets.APP_PORT }} ${{ env.REPOSITORY_FULL_NAME }}:latest

I hope this information has been useful to you 😉

I faced the same issue as well (while having none with appleboy/scp-action) and was eventually able to resolve this by reconfiguring ufw on my server. The action for 22/tcp was LIMIT for some reason.

Running

sudo ufw allow ssh

fixed it for me.

Using GCP where I have ssh allowed on instance firewall and executed sudo ufw allow ssh, checked it was enabled with sudo ufw status and it is. Still facing timeout issue.

I was facing the same issue and I have solved it… I have first used @Shaance’s way then I have changed inbound and outbound for EC-2 instance ( Security Groups). Some other debugging and bingo it works now… Thanks to all

I’m getting the same error. Trying to connect to a Windows Server 2008 r2 with freesshd on it.