8000 [Worker support] test for no cors headers by madhur-tandon · Pull Request #1374 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

[Worker support] test for no cors headers #1374

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

Merged
merged 14 commits into from
May 2, 2023

Conversation

madhur-tandon
Copy link
Member
@madhur-tandon madhur-tandon commented Apr 10, 2023

Closes #1312 and #1364

CC: @hoodmane and @antocuni

< 8000 svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo-push">
madhur-tandon and others added 2 commits April 10, 2023 19:53
@madhur-tandon madhur-tandon added the sprint issue has been pulled into current sprint and is actively being worked on label Apr 10, 2023
Copy link
Contributor
@antocuni antocuni left a comment

Choose a reason for hiding this comment

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

The code in the PR is good, apart some naming/style minor issue which I highlighted in the comments.

But the big problem is the 8000 code which is NOT in the PR: what we want is that pyscript detects the "no cors" headers and display a nice error message, with a link to the documentation which explains what is the problem.
This is just the machinery to make it possible to write a test for that, but the machinery alone is useless.

@hoodmane
Copy link
Contributor

I don't think this does resolve #1312. The feature request is:

display a nice and error message (ideally with a link to a detailed page in our documentation) to explain what's the problem

When the headers are missing. As far as I can tell this patch only adjusts test code, it doesn't currently add any new error messages.

Also we should consider further improvements to synclink so that in same thread mode shared array buffer isn't needed.

@hoodmane
Copy link
Contributor

This is a useful step towards resolving #1312 though, it gets the test support code ready.

@madhur-tandon
Copy link
Member Author

Aah sorry, seems like I missed the part about introducing error messages in #1312

@antocuni
Copy link
Contributor

@madhur-tandon I think there is a bit of confusion w.r.t the final goal. In theory, the current situation is the following:

  1. PyScript uses Synclink which uses SharedArrayBuffer, which is available only under certain conditions
  2. those conditions depends on the web server which servers the HTML page, and which we (PyScript OSS developers) have no control upon
  3. if an user develops a pyscript app and deploys it to a webserver which does NOT send the required headers, the page would not work because it cannot find SharedArrayBuffer
  4. in that case, we want to display a nice error message to the user, using an alert banner similar to what we display in case of UserError.
  5. we want to write a test which checks that we actually display the error in case (4)

HOWEVER

I realized that we cannot write such a test currently, because situation (4) never arises: i.e., currently pyscript works perfectly fine even if we don't have CORS headers set. I think we will need it as soon as we merge PR #1333 , but not today.

@hoodmane I am very confused about what's happening on main currently. Synclink seems to have some fallback to use ArrayBuffer if SharedArrayBuffer is not available:
https://github.com/pyodide/synclink/blob/f26bfa33139bf9209cad9df5c03a4994fbc62c95/src/shared_array_buffer.ts#L1-L7

But then my question is: why did you have to modify HTTPServer in the synclink branch? In particular:

class MyHTTPRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
def log_message(self, fmt, *args):
logger.log("http_server", fmt % args, color="blue")
host, port = "localhost", 8080

If I comment out self.send_my_header() and revert host to 127.0.0.1, the tests seems to work flawlessly. So I suppose that that change was not strictly necessary?

@madhur-tandon
Copy link
Member Author

@antocuni Although I have added the error message, it is not in the form of a UserError / alert banner.
If you have time, can you review this again?
Although PyScript works fine even if we don't have headers set, but I made sure to still check if our dev web server / fake server supplies them or not and we then do a console.error in case they do not.

Tagging @hoodmane too for a re-review as well.

The right entry point to check for these headers is the goto() function IMO
The commit where I added the error message is here: 97bc5d5

@hoodmane
Copy link
Contributor

So I suppose that that change was not strictly necessary?

Sounds like.

@antocuni
Copy link
Contributor

@antocuni Although I have added the error message, it is not in the form of a UserError / alert banner.

@madhur-tandon see my previous message:
#1374 (comment)

The source of the confusion is a big misunderstanding: the synclink PR added the CORS headers to our dev server, so I assumed they were necessary for running pyscript: and in that case, the point of #1312 was to make sure that we display a nice error message to the user.

But it turns out that it's not the case: as of now, the CORS headers are not needed and pyscript works perfectly fine without them. So the "proper" fix would be to revert the change and delete the extra code from the repo, not to add a test for an unneeded feature.

However, the situation is going to change soon: CORS headers are needed for web workers, so as soon as #1333 is merged, this PR becomes relevant again. Let's put it on hold until then.

@antocuni antocuni changed the title test for no cors headers [Worker support] test for no cors headers Apr 13, 2023
@madhur-tandon
Copy link
Member Author

The tests that fail are kinda unrelated 😅

@madhur-tandon
Copy link
Member Author

@antocuni and @hoodmane requesting a re-review. Thanks!

Copy link
Contributor
@FabioRosado FabioRosado left a comment

Choose a reason for hiding this comment

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

Looks good to me 😄

Copy link
Contributor
@hoodmane hoodmane left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@hoodmane
Copy link
Contributor

After we merge let's open an issue to add a place in the docs somewhere with more info and put a link to it in the error message.

@madhur-tandon madhur-tandon requested a review from antocuni April 28, 2023 09:06
Copy link
Contributor
@antocuni antocuni left a comment

Choose a reason for hiding this comment

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

LGTM

@madhur-tandon madhur-tandon merged commit cd1aa94 into pyscript:main May 2, 2023
@madhur-tandon madhur-tandon deleted the cors-test branch May 2, 2023 13:13
@madhur-tandon madhur-tandon self-assigned this May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sprint issue has been pulled into current sprint and is actively being worked on
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

[Worker support] Add a test for missing CORS headers
4 participants
0