Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

fix reading multiple responses #44

Merged
merged 17 commits into from
Jun 17, 2022
Merged

fix reading multiple responses #44

merged 17 commits into from
Jun 17, 2022

Conversation

petar
Copy link
Collaborator

@petar petar commented Jun 7, 2022

Addresses ipfs/someguy#1

@petar petar marked this pull request as ready for review June 10, 2022 18:19
@aschmahmann
Copy link

@petar on the server end there also seems to be a need for flushing the HTTP writes or they don't actually make it to the other side. Discovered by testing this in someguy.

Perhaps adding some code like this after each write would do the job. We should probably add a test for this as well.

if f, ok := writer.(http.Flusher); ok {
	f.Flush()
}

@petar
Copy link
Collaborator Author

petar commented Jun 13, 2022

@petar on the server end there also seems to be a need for flushing the HTTP writes or they don't actually make it to the other side. Discovered by testing this in someguy.

Perhaps adding some code like this after each write would do the job. We should probably add a test for this as well.

if f, ok := writer.(http.Flusher); ok {
	f.Flush()
}

I've added the flush. It's not very clear how to test this though. I already had a test for multiple responses using the httptest.NewServer, which passes without the flush. Was there anything special about the setup where you ran into this? If it's just a vanilla HTTP/TCP connection, we could try adding a test that uses http.NewServer (as opposed to httptest.NewServer).

@aschmahmann
Copy link

It's not very clear how to test this though.

Have a data source for records where it'll give you the first record and for the second record it just stalls (and therefore the server never returns). See if the client actually gets a record or not. If it does then return (and cancel contexts), if it doesn't return after a while (e.g. a second) then error.

Was there anything special about the setup where you ran into this?

The data source my server was streaming from had asynchronous outputs that took a while to complete (i.e. DHT queries that give provider record results almost immediately but spend a while completing the query to look for more provider records).

@petar
Copy link
Collaborator Author

petar commented Jun 15, 2022

@aschmahmann I've added the test. While working on it, I noticed another behavior to be conscious of:
If client A connects to server B and has a long-running connection (e.g. multiple slow async responses), then another concurrent request from client A to B may stall, I think because Go's HTTP library tries to reuse the connection, but it is busy. So when Reframe is used, the HTTP stack should be explicitly configured to not reuse connections!

@petar petar merged commit d34b6b5 into main Jun 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants