Websocket+HTTP/2 error with cloudflare load balancing

Open
#2,888 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
networking

Research direction

Start by reviewing tornado/simple_httpclient.py around line 658 and reproduce the reported WebSocket request with the curl commands, comparing HTTP/2 and HTTP/1.1 behavior. The report does not define a concrete code change or completion condition, so the expected fix would need to be clarified before implementation.

Written by the indexing model from the issue text.

Description

websocket

I didn't find much online about this, but when connecting through cloudflare to a tornado WebSocket handler I received these headers:

Host: dataframe.vaex.io
X-Real-Ip: 141.101.105.77
X-Forwarded-For: 89.188.19.102, 141.101.105.77
Connection: upgrade
Accept-Encoding: gzip
Cf-Ipcountry: NL
Cf-Ray: 5afa07af2b3cbd82-AMS
X-Forwarded-Proto: https
Cf-Visitor: {"scheme":"https"}
User-Agent: curl/7.68.0
Accept: */*
Origin: http://dataframe.vaex.io
Cf-Request-Id: 03d02321780000bd82a2118200000001
Cf-Connecting-Ip: 89.188.19.102
Cdn-Loop: cloudflare

After which you get the error Connection" must be "Upgrade". The stacktrace in tornado is pretty vague (self.client is None at https://github.com/tornadoweb/tornado/blob/ad6e4acf9eb0df6a07f48fddd5945510bcd4a555/tornado/simple_httpclient.py#L658).

But using curl helped:

$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: dataframe.vaex.io" -H "Origin: http://dataframe.vaex.io" https://dataframe.vaex.io/websocket

Note the https

https://community.cloudflare.com/t/websocket-pass-through-crashes-worker-script/78482/7 gave me a hint to disable http2:

$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: dataframe.vaex.io" -H "Origin: http://dataframe.vaex.io" https://dataframe.vaex.io/websocket --http1.1  

This worked 🎉

I didn't see an option to choose the HTTP version in tornado, so i disabled https in cloudflare, and I now don't have an issue.

Sorry for the low quality hasty, report. I am in a hurry, but it might be useful for the author(s) or someone with similar issues.

Dominant language
Python
Stars
22.2k
Forks
5.6k
Avg merge
3h 42m
Merged PRs (30d)
16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tornadoweb/tornado

All issues in tornadoweb/tornado

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.