Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potentially fix timeouts/retries when fetching from remote #304

Merged
merged 9 commits into from
Sep 25, 2024

Conversation

btkostner
Copy link
Contributor

Description

This action uses node 20, which now has the built in fetch implementation. We can use that instead of the @action/http-client package. This allows us to do our own retry implementation to fix the long standing issue #260.

Closes issue: #260

@paulo-ferraz-oliveira paulo-ferraz-oliveira linked an issue Sep 20, 2024 that may be closed by this pull request
@paulo-ferraz-oliveira
Copy link
Collaborator

👋 Is there a mechanism (even if very dumb/simple) to try and test this?

@btkostner
Copy link
Contributor Author

@paulo-ferraz-oliveira Looks like GH can just pull directly from the branch and everything should work. So try instead of using erlef/setup-beam, do btkostner/setup-beam@retry and see if that works.

Comment on lines 571 to 575
if (contentType.indexOf('application/json') !== -1) {
return response.json()
} else {
return response.text()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the automatic JSON decoding was the only real feature we needed.

Comment on lines 567 to 569
if (!response.ok) {
throw new Error(`Got ${response.statusCode} from ${url}`)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking if the response is ok or not. We can get more detailed with status code checking if we need, but I don't see a reason.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we weren't getting more detail no more detail is required, at this moment. There's been requests to include more detail around errors, but that's for a different pull request.

}
async function getUrlResponse(url, headers, attempt = 1) {
try {
const response = await fetch(url, { headers })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fetch will throw an error on timeout, so that's why we are wrapping. Open to other options / ideas to make this cleaner.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try-catch should be Ok here. This is not a huge script, and the handling is isolated.

src/setup-beam.js Outdated Show resolved Hide resolved
@paulo-ferraz-oliveira
Copy link
Collaborator

It'll work if CI passes, I'm not worried about that bit. I was thinking of what we could do to have reliable repeatable tests.

@btkostner
Copy link
Contributor Author

@paulo-ferraz-oliveira Added a test using the built in node server. Verified it is working as intended locally. I added a 10 second timeout to fetch calls, though the original code had a 3 minute socket timeout by default which seems very long.

https://github.com/actions/toolkit/blob/6dd369c0e648ed58d0ead326cf2426906ea86401/packages/http-client/src/index.ts#L531

@btkostner btkostner marked this pull request as ready for review September 21, 2024 00:11
Copy link
Collaborator

@paulo-ferraz-oliveira paulo-ferraz-oliveira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, in general. I'll let other repo collaborators review too, since I might've missed something. I'll add them as reviewers.

@paulo-ferraz-oliveira
Copy link
Collaborator

paulo-ferraz-oliveira commented Sep 24, 2024

D'you wanna be a pal and remove the failing test from CI? It happens because we're targetting OTP 24 and rebar3 3.24 doesn't support it.

And would you also update test/.tool-versions to more recent versions?

If not, I can do both, but you'd have to rebase later... 👍

@btkostner
Copy link
Contributor Author

Looks like something is installing rebar3 and the action does not like that. I'd say it's another issue that should be addressed in another PR. Probably something about force overwriting files when installing.

@wojtekmach wojtekmach merged commit 2fdf20c into erlef:main Sep 25, 2024
61 of 62 checks passed
@wojtekmach
Copy link
Collaborator

Thank you!

I'll fix the test failure on main. We have this line for rebar:

fs.mkdirSync(bindir)

and we're doing it twice on CI, once for npm test step and once for .tool-versions test step. I'll change it to:

fs.mkdirSync(bindir, { recursive: true })

wojtekmach added a commit that referenced this pull request Sep 25, 2024
@btkostner btkostner deleted the retry branch September 25, 2024 17:02
@paulo-ferraz-oliveira paulo-ferraz-oliveira changed the title feat: setup custom retry with builtin node fetch Potentially fix timeouts/retries when fetching from remote Sep 25, 2024
@paulo-ferraz-oliveira
Copy link
Collaborator

Released in v1, v1.18 and v1.18.2. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Action sporadically times out when fetching Ubuntu
3 participants