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

[Apple's Broken Compression Handling] NSPOSIXError when trying to connect from Damus #3

Closed
syobocat opened this issue Jul 28, 2024 · 10 comments
Labels
good first issue Good for newcomers

Comments

@syobocat
Copy link

Hello.
When I try to connect to a bouncer from Damus app, it fails with Error: Error Domain=NSPOSIXErrorDomain Code=100 "Protocol error" UserInfo={NSDescription=Protocol error} and Damus attempts to reconnect over and over.

Here is the screenshot:
スクリーンショット 2024-07-28 20 27 52

My bostr2 instance is running with Go 1.21.12 on 14.1-RELEASE-p2, and is behind Caddy and Cloudflare.

@Yonle
Copy link
Owner

Yonle commented Jul 28, 2024

This is strange. Try paste logs printed on the bostr2 server.

@Yonle
Copy link
Owner

Yonle commented Jul 28, 2024

Just checked, The error 100 is referring to failed HTTP/2 connections.

It looks like it's trying to connect with HTTP/2, which is not supported by nhooyr.io/websocket lib yet
Screenshot_20240728-202708.jpg

@Yonle Yonle added the good first issue Good for newcomers label Jul 28, 2024
@Yonle
Copy link
Owner

Yonle commented Jul 28, 2024

You could try restart bostr2 with GODEBUG=http2server=0 environment variable being set.

@Yonle Yonle pinned this issue Jul 28, 2024
@Yonle Yonle changed the title NSPOSIXError when trying to connect from Damus [http2 problem] NSPOSIXError when trying to connect from Damus Jul 28, 2024
@syobocat
Copy link
Author

I set GODEBUG=http2server=0 and restarted bostr2, but I still got the same error.

Also, I tried connecting to the server directly (without any reverse proxy), but the result was the same, too.

スクリーンショット 2024-07-28 23 29 05

Here is the log bostr2 printed:

⋮
2024/07/28 22:54:57 172.70.122.72 connected (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 22:54:57 172.70.122.72: failed to get reader: failed to read frame header: EOF
2024/07/28 22:54:57 172.70.122.72 disconnect (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 22:54:59 162.158.118.73 connected (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 22:55:00 162.158.118.73: failed to get reader: failed to read frame header: EOF
2024/07/28 22:55:00 162.158.118.73 disconnect (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 22:55:02 172.68.118.227 connected (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 22:55:02 172.68.118.227: failed to get reader: failed to read frame header: EOF
2024/07/28 22:55:02 172.68.118.227 disconnect (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 22:55:04 172.70.222.139 connected (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
⋮

If I try connecting directly, it shows a slightly different message:

⋮
2024/07/28 23:32:16 192.168.0.221:52741 connected (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 23:32:16 192.168.0.221:52741: failed to get reader: received close frame: status = StatusProtocolError and reason = ""
2024/07/28 23:32:16 192.168.0.221:52741 disconnect (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 23:32:18 192.168.0.221:52743 connected (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 23:32:18 192.168.0.221:52743: failed to get reader: received close frame: status = StatusProtocolError and reason = ""
2024/07/28 23:32:18 192.168.0.221:52743 disconnect (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 23:32:19 192.168.0.221:52744 connected (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 23:32:19 192.168.0.221:52744: failed to get reader: received close frame: status = StatusProtocolError and reason = ""
2024/07/28 23:32:19 192.168.0.221:52744 disconnect (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
2024/07/28 23:32:21 192.168.0.221:52745 connected (damus/14 CFNetwork/1496.0.7 Darwin/23.5.0)
⋮

@Yonle Yonle changed the title [http2 problem] NSPOSIXError when trying to connect from Damus NSPOSIXError when trying to connect from Damus Jul 28, 2024
@Yonle
Copy link
Owner

Yonle commented Jul 28, 2024

Majority of servers out here are using HTTP/1.1, and they worked most of the time.

I checked the connection, Nothing wrong with header nor status.

Just added an option to stop serving invalid Upgrade header. I have no idea whenever it would made any difference.

Either way, You could test with the recent commit on master. Clone this repository, go install ., try restart and see will it make any difference.

If still persist, and this problem is not able to be reproduced on bostr, Then my final guessing is the problem is on nhooyr's websocket lib.

@Yonle
Copy link
Owner

Yonle commented Jul 28, 2024

Looks like it has something to do with compression.

coder/websocket#218

@Yonle
Copy link
Owner

Yonle commented Jul 28, 2024

Disabled compression due to it being unreliable at very certain cases. Could you try again with the recent commit?

@Yonle Yonle changed the title NSPOSIXError when trying to connect from Damus [Apple's Broken Compression Handling] NSPOSIXError when trying to connect from Damus Jul 28, 2024
@Yonle
Copy link
Owner

Yonle commented Jul 28, 2024

Added a code that disables compression on apple while keeping it on for others.

Well well well.

Right now, It should've fixed. But not a good fix unfortunately.

@Yonle
Copy link
Owner

Yonle commented Jul 28, 2024

Fixed on v1.0.1

@Yonle Yonle closed this as completed Jul 28, 2024
@Yonle Yonle unpinned this issue Jul 28, 2024
@syobocat
Copy link
Author

I tried 1.0.1 and it worked as expected.
Thank you so much!

Yonle added a commit to Yonle/bostr that referenced this issue Jul 29, 2024
Preparing before disaster happens.
See Yonle/bostr2#3

Signed-off-by: Yonle <yonle@lecturify.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants