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

Verify sha before cache write #2112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vondele
Copy link
Member

@vondele vondele commented Jul 7, 2024

No description provided.

@vondele
Copy link
Member Author

vondele commented Jul 7, 2024

works, must be seen if this resolves https://tests.stockfishchess.org/actions?max_actions=1&action=&user=&text=validate&before=1720333358.645925&run_id=

where a corrupted net ends up in the cache. Not clear how this can happen, at least this check will exclude the download part of the issue

@vdbergh
Copy link
Contributor

vdbergh commented Jul 7, 2024

It should solve the issue. The request package may create corrupt downloads.

@vondele
Copy link
Member Author

vondele commented Jul 7, 2024

but can it do without triggering an error (i.e. we call raise_for_status)?

Edit we do similar stuff for the zipballs we get from github, and somehow we can't as easily verify those.

Edit, we could probably try to unzip them.

@vdbergh
Copy link
Contributor

vdbergh commented Jul 7, 2024

I think it can although the mechanics are not clear to me. I suppose the library receives the correct http headers but then the download is aborted. But in principle the library should be able to verify that the correct number of bytes has been received.

@vdbergh
Copy link
Contributor

vdbergh commented Jul 7, 2024

Or maybe there is a bug in the error handling in the worker (I.e. an error is raised but not handled correctly). Can't check now. Traveling.

@vdbergh
Copy link
Contributor

vdbergh commented Jul 7, 2024

It seems older versions of the requests package did not check content length. Could it be that the requests package in the worker is outdated?

@vondele
Copy link
Member Author

vondele commented Jul 7, 2024

__version__ = '2.25.1' is in our repo

@ppigazzini
Copy link
Collaborator

ppigazzini commented Jul 7, 2024

That request version was the last compatible one with python 3.6.8 used by noob's workers.
However, local installed packages should still have the priority respect to the shipped packages (expression should be the only exception)

# Fall back to the provided packages if missing in the local system.
packages_dir = Path(__file__).resolve().parent / "packages"
sys.path.append(str(packages_dir))

@vdbergh
Copy link
Contributor

vdbergh commented Jul 7, 2024

Last version on pypi is 2.32.3.

@vondele
Copy link
Member Author

vondele commented Jul 7, 2024

psf/requests#4956

so yeah, I think we're running into this.

@vdbergh
Copy link
Contributor

vdbergh commented Jul 7, 2024 via email

@vondele
Copy link
Member Author

vondele commented Jul 7, 2024

looking into that... it is non-trivial.

@vondele
Copy link
Member Author

vondele commented Jul 7, 2024

giving up on checking the content-length, I don't get it to work (seems like it can depend on encoding, etc).

@vdbergh
Copy link
Contributor

vdbergh commented Jul 7, 2024

@vdbergh
Copy link
Contributor

vdbergh commented Jul 7, 2024

Ok I see. You cannot check it with the length of the downloaded file.

@vondele
Copy link
Member Author

vondele commented Jul 7, 2024

extend the original PR by moving the write of zipballs to after they have been unzipped and thus effectively been verified. Now both blobs written to cache are known to be OK.

The bundled request package doesn't verify the content downloaded is complete.
Hence verify that that content is correct before storing it to cache.
For the net perform a sha verify, for the zipball unzip first.
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.

3 participants