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

cmd/syncthing: Use ReadAll + json.Unmarshal in places were we care about consuming the reader #3050

Closed
wants to merge 1 commit into from

Conversation

calmh
Copy link
Member

@calmh calmh commented May 6, 2016

Purpose

Because json.NewDecoder(r).Decode(&v) doesn't necessarily consume all data on the reader, that means an HTTP connection can't be reused. We don't do a lot of HTTP traffic where we read JSON responses, but the discovery is one such place. The other two are for POSTs from the GUI, where it's not exactly critical but still nice if the connection still can be keep-alive'd after the request as well.

Also ensure that we call req.Body.Close() for clarity, even though this should by all accounts not really be necessary.

Testing

Unpossible to fail

…out consuming the reader

Because json.NewDecoder(r).Decode(&v) doesn't necessarily consume all
data on the reader, that means an HTTP connection can't be reused. We
don't do a lot of HTTP traffic where we read JSON responses, but the
discovery is one such place. The other two are for POSTs from the GUI,
where it's not exactly critical but still nice if the connection still
can be keep-alive'd after the request as well.

Also ensure that we call req.Body.Close() for clarity, even though this
should by all accounts not really be necessary.
@AudriusButkevicius
Copy link
Member

@st-review merge

@st-review
Copy link

👌 Merged as 39899e4. Thanks, @calmh!

st-review pushed a commit that referenced this pull request May 6, 2016
…out consuming the reader

Because json.NewDecoder(r).Decode(&v) doesn't necessarily consume all
data on the reader, that means an HTTP connection can't be reused. We
don't do a lot of HTTP traffic where we read JSON responses, but the
discovery is one such place. The other two are for POSTs from the GUI,
where it's not exactly critical but still nice if the connection still
can be keep-alive'd after the request as well.

Also ensure that we call req.Body.Close() for clarity, even though this
should by all accounts not really be necessary.

GitHub-Pull-Request: #3050
@st-review st-review closed this May 6, 2016
@calmh calmh deleted the unmarshal branch May 8, 2016 17:03
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jun 16, 2017
@syncthing syncthing locked and limited conversation to collaborators Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants