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

Enable full duplex for http1 connections #692

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

withinboredom
Copy link
Collaborator

@withinboredom withinboredom commented Mar 28, 2024

There are two things here:

  1. Per fix reading post bodies #686 (comment), we can let caddy handle the duplexity of http1. So the Caddyfile is updated to include this by default.
  • check the documentation for caddyfile references and update if necessary
  1. An empty body was actually impossible to "read" (file_get_contents('php://input') didn't even work), thus causing things like Server-Sent-Events not working through HTTP/1.1 #690 to be unable to work for http1 connections.
  • triple check for other cases like this

kudos: @francislavoie

fixes: #690

@francislavoie
Copy link
Contributor

Might need to wait for Caddy v2.8.0 due to caddyserver/caddy#6102

Also keep in mind that some HTTP clients may not support duplex for HTTP/1.1 properly. I don't know the specifics of this, but that's the reason it's not enabled by default by Go. I haven't played around with this much at all, we just added the config flag to enable it for users to try out as a possible solution for those edgecases.

@withinboredom
Copy link
Collaborator Author

withinboredom commented Mar 28, 2024

Also keep in mind that some HTTP clients may not support duplex for HTTP/1.1 properly.

I'm a bit skeptical of this; IIRC on the nginx implementation, it always reads the entire body (and always had -- hence the client_max_body_size directive). I'm not 100% sure as http1 is pretty ancient at this point, though still used. There may also be some magic via output buffers to provide an illusion of duplex in nginx... but anyway, I suspect the vast majority of HTTP clients (e.g., curl and friends) probably support it out-of-the-box. There may be custom implementations out there that don't support it, but they are probably an epic minority.

(edit to add: might just be wishful thinking as well. I currently have no evidence of this.)

@dunglas
Copy link
Owner

dunglas commented Mar 30, 2024

I would like to be in sync with Caddy regarding the defaults.
As it looks like it's breaking a lot of Laravel apps, maybe Caddy should also consider enabling this feature by default anyway (cc @mholt @francislavoie). Otherwise, maybe should we just document how to enable this feature to fix the apps using SSE?

@francislavoie
Copy link
Contributor

I would be willing to enable it by default, but we need to make an evidence based decision. We don't know if it would break anything. Plus if it does break things it would probably do so quite obscurely; users would not think to try disabling duplex. Also I kinda rather follow the Go defaults rather than flip them, that becomes confusing.

@dunglas
Copy link
Owner

dunglas commented Mar 30, 2024

I agree. @withinboredom can we stick to Caddy and Go defaults please?

caddy/frankenphp/Caddyfile Outdated Show resolved Hide resolved
@withinboredom
Copy link
Collaborator Author

Updated documentation about enable_full_duplex and removed it from the default caddyfile.

Copy link
Owner

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

LGTM! I added some tiny docs improvements.

docs/config.md Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
docs/config.md Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
withinboredom and others added 6 commits April 9, 2024 14:38
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
@withinboredom
Copy link
Collaborator Author

Hmm. Would you be opposed to a PR that cancels builds if another commit is added to a PR? I used the GitHub ui to merge your suggestions which kicked off a bunch of builds. It'd probably be more efficient to only build the last commit and cancel the others.

@dunglas
Copy link
Owner

dunglas commented Apr 9, 2024

No, good idea!

@withinboredom
Copy link
Collaborator Author

So, two notes:

  1. I spotted a segfault on one of the test runs. It looks unrelated to this PR, but there's likely a nil pointer somewhere causing it. I'll take a look tomorrow, most likely. I'm still pretty sick but nearly recovered, though my throat is ragged af and I still have a lingering cough.
  2. it looks like the static builder is (nearly) completely broken atm, not sure why. Would adding --debug to the builder also build it in debug mode or will it just allow us to see the errors? If it also builds it in debug mode, we should probably open an issue to just allow seeing the full build output. For CI purposes, hiding the build output is rather pointless.

Neither of these issues seems like a blocker to merge. If you agree @dunglas, give me a 👍 or merge away!

@dunglas
Copy link
Owner

dunglas commented Apr 10, 2024

I hope you'll get better soon and wish you a speedy recovery. Take your time, there is no urgency at all in the pending PR.

Regarding this one, shouldn't we wait for the next release of Caddy to merge this?

LGTM otherwise!

Do you have more informations about the segfault you get? I can try to track it.

@withinboredom
Copy link
Collaborator Author

shouldn't we wait for the next release of Caddy to merge this?

Yeah, good call!

Do you have more informations about the segfault you get?

I've been trying to reproduce it. No luck so far.

@withinboredom
Copy link
Collaborator Author

Looking at https://github.com/dunglas/frankenphp/actions/runs/8622010633/job/23632166418 and the stack trace a bit closer, it looks like the nil is in the test library itself, not our code.

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.

Server-Sent-Events not working through HTTP/1.1
3 participants