-
Notifications
You must be signed in to change notification settings - Fork 42
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
set the connection close header if we have a body to read #116
Conversation
This should probably have tests. |
I'm wondering how this is different from disabling keep alives on the server? I haven't read too closely, but Also, this is equivalent to asking the client to close the connection but you will need the client to comply (hopefully). Wouldn't it be better to close server-side? |
Basically, if we set Ideally, we'd only do this if they've sent us a body and we decide to send back a response before reading the rest of the request. However, harder to implement. |
@keks thoughts? |
Wow this is a tricky one.
We could check this in the http response emitter |
I think so... Feel free to take this over and try it. |
@keks does this look good to go as a stop-gap so we can fix the current issue? |
@Stebalien sorry I had an exam on Wednesday. Looking into it right now. |
Np. |
I'm still thinking whether we can come up with a good unit test for this... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of writing the error to the channel, we may want to consider simply closing it on EOF (unless we just want to assume that we can't have multiple errors).
http/responseemitter.go
Outdated
// FIXME: https://github.com/golang/go/issues/15527 | ||
if re.bodyErrChan != nil { | ||
select { | ||
case <-re.bodyErrChan: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we can get transient errors (e.g., read timeouts). We probably do just want to check for an EOF and assume that other errors mean there may be more data. In all likelihood, any non-EOF error means the connection is in trouble anyways.
http/handler.go
Outdated
// FIXME: https://github.com/golang/go/issues/15527 | ||
var bodyErrChan chan error | ||
if r.Body != http.NoBody { | ||
bodyErrChan = make(chan error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a buffer.
Weird. I added a check that the handler actually sets the "Connection: close" header, but the client doesn't see it. However, when I look at the test coverage, the line where the header is set is green, so the handler really should set it. |
I don't get why I can't comment inline, but whatever....
In the else case the channel is nil (it's only |
@Stebalien have you seen my previous comment? |
I have, I just have no idea what's going on either. |
Hm? I commented on your review remark, and I think your request for change is not necessary. Do you agree? If not, why? |
Ah, yes, you were right. That looks correct. |
f493069
to
1fa542c
Compare
1fa542c
to
6cc571e
Compare
@keks any chance we can get this moving? The tests aren't currently passing but we need to get some fix for this in. |
We can't stream a response while reading a body *unless* we've configured the connection to close after we're done sending a response. This patch works around that issue by doing exactly that.
6cc571e
to
9b24e5d
Compare
Ok, I've finally found the issue (go swallows the connection close header and sticks it in the response object). |
@keks wrote the final version so I'll give it a ✔️ review. |
We can't stream a response while reading a body unless we've configured the connection to close after we're done sending a response.
This patch works around that issue by doing exactly that.
Fixes: ipfs/kubo#5168 (sort of)