-
Notifications
You must be signed in to change notification settings - Fork 150
[bugfix] Hop by hop header handling #328
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
[bugfix] Hop by hop header handling #328
Conversation
Thanks for submitting your first pull request! You are awesome! 🤗 |
Thanks for this PR @mahnerak and the thorough explanation! It makes a lot of sense to me. I found RFC 2616, 13.5.1 which corroborates the hop-by-hop header list. That RFC was superseded in 2014 (more), but the ones that replaced it don't spell out the full list. Could you please add a comment which links to the (apparently outdated) RFC anyways? Or maybe whatever else is more authoritative, though I don't know what that is. Apparently |
Thanks @ryanlovett for the comment.
Sure! Also, the current Let's add links to:
I'll make sure to include a comment for |
One more thing on: |
Just as a note, I found that during writing my own workaround for this bug that in addition to stripping the Transfer-Encoding header I had to provide a correct Content-Length header as well. i.e., I added something like this: if 'Transfer-Encoding' in headers:
del headers['Transfer-Encoding']
if body is not None:
headers['Content-Length'] = len(body) Just wanted to relay this information in case it's useful. |
Any progress on this? Also the notebook app FiftyOne seems to be broken by this as well. |
Thanks a lot for this, @mahnerak! I'm happy to merge this once #328 (comment) is accepted. I'm not able to accept it myself for some reason - perhaps the 'allow maintaieners to push to this PR' option is not enabled for this PR? |
@yuvipanda Let me check it for you. |
Co-authored-by: Yuvi Panda <[email protected]>
@yuvipanda I couldn't find |
Thanks a lot, @mahnerak! |
Anyone know if this update alone enables things like Tensorboard cell magic or Flask apps in SageMaker? |
In SageMaker Notebook several ML tools do not work, including
aim
,lit
,mlflow
,streamlit
, etc.The reason:
jupyter-server-proxy
fails on POST requests if the client sends the body usingTransfer-Encoding: chunked
.TensorBoard
does work only because of a workaround solution of replacing all thePOST
requests withGET
s.In more detail:
The
Transfer-Encoding
is used by http client to specify whether thePOST
method streams without need of knowing content length ahead of time.Client request path is roughly:
Now, forwarding some headers, including
Transfer-Encoding
is wrong because the transfer encoding between[2]->[3]
can be different from[3]->[4]
. In our case,SageMaker
does always useTransfer-Encoding: chunked
forPOST
requests which makes it to overrideTransfer-Encoding
header value of request[3]->[4]
while the http client used by[3]
does not have to change the actual transfer encoding accordingly (it simply overrides headers).When receiving
POST
request body by[4]
it fails to decode the data because although the header specifies chunked , the body is encoded as a whole, not in chunks (by usingContent-Length
to detect end of message instead of\r\n
sentinels) .The
HTTP
standard defines https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding asHop-By-Hop header
(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#hop-by-hop_headers) thus must not be retransmitted by proxies or cached. In other http proxy implementations such assquid
,node-http-proxy
, etc. such headers are removed prior to sending to endpoint.This PR focuses on removing not only
Transfer-Encoding
but all hop-by-hop headers to avoid such conflicts.Note: SageMaker does not come with the latest
jupyter-server-proxy
. But the issue persists even after upgrading.References:
[Bug] Aim UI not opening on Sagemaker Notebook aimhubio/aim#1336
Plotly Dash host/proxy issue in SageMaker aws/amazon-sagemaker-examples#1595
AWS SageMaker plotly/jupyter-dash#39
Can't connect to Streamlit server awslabs/sagemaker-explaining-credit-decisions#6
Unable to run mlflow behind jupyter-server-proxy mlflow/mlflow#1120
Unknown error when browsing the tool - Using AWS Sagemaker Notebook instances PAIR-code/lit#41
https://github.com/tensorflow/tensorboard/blob/master/tensorboard/webapp/webapp_data_source/tb_http_client.ts#L97-L100