Curl --max-time
I was setting up a GitHub workflow to ping a service every N seconds to keep it alive. On the free tier, GitHub gives about 2000 minutes per month, which I thought would be enough. The core of the workflow was just:
curl -s https://myservice.example > /dev/null
I tested it a few times and it finished in a couple of seconds, so I let it run. When I checked
back the next day, I saw it had used over 30 minutes in 24 hours. That was weird. That’s when I
realzied sometimes curl would just hang for several minutes until the service became reachable.
I hadn’t realized curl had a --max-time option to limit how long it’s allowed to run before
timing out.
I ended up with this:On top of that, I added the timeout-minutes option to the GitHub workflow and ended up with this:
name: Ping
on:
schedule:
- cron: "*/25 * * * *"
workflow_dispatch:
jobs:
ping:
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: ping
run: |
curl --max-time 10 --connect-timeout 5 -s https://myservice.example/ > /dev/null
So if you’re on the free tier, like me, make sure to handle timeouts!