-
Notifications
You must be signed in to change notification settings - Fork 260
Fix incorrect empty body provided to Wireserver #1728
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
Fix incorrect empty body provided to Wireserver #1728
Conversation
In cases where clients using a WireserverTransport (namely the NMAgent one) do not wish to provide a body, one must be provided to satisfy quirks of Wireserver. Initially, an empty Go string was thought to be sufficient, but this is not. Wireserver expects an empty JSON string: specifically the 2-byte sequence "". Furthermore, this logic was only being triggered on cases where a nil body was presented to the WireserverTransport's logic. Given that there are now more linters enforcing the use of `http.NoBody`, this is distinct from `nil` and must be separately checked for (but treated in the same way). Tests and inline documentation have been updated to reflect this new understanding.
rbtr
left a comment
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.
horrible
Because the Body of the request was replaced, Go also has no idea what the content type should be. It can't read from the reader to perform the detection, so this just sets it to JSON manually. As mentioned in the comments, this is a good idea anyway since we're being explicit rather than relying on heuristic methods to do the right thing.
| t.Error("downstream request body to wireserver was nil, but not expected to be") | ||
| exp := `""` // an empty JSON string | ||
| if got := string(gotBody); got != exp { | ||
| t.Errorf("unexpected body received: got: %q, exp: %q\n", got, exp) |
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.
nit: is the new line needed? same for others.
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.
@ramiro-gamarra do you mean the changed content, or a literal \n? There are no extra \ns (look at the line number sequence). It might be a GH display bug.
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.
the \n in the error message
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.
Okay, so apparently, the presence or absence of it makes no difference in the output--they're stripped internally. I add them out of habit it because it matters for fmt.Println vs fmt.Printf. Since it won't create janky output, I'll keep it in mind for next time, but I won't fix it here to avoid blocking the merge.
|
This fix works for us. Have tested by building a CNS executable and joinNetwork calls do not fail anymore. |
|
This is fixing a regression in the master which has caused the releases 1.4.38 and 1.4.39 as non-usable for swift standalone. |
In cases where clients using a WireserverTransport (namely the NMAgent one) do not wish to provide a body, one must be provided to satisfy quirks of Wireserver. Initially, an empty Go string was thought to be sufficient, but this is not. Wireserver expects an empty JSON string: specifically the 2-byte sequence "". Furthermore, this logic was only being triggered on cases where a nil body was presented to the WireserverTransport's logic. Given that there are now more linters enforcing the use of `http.NoBody`, this is distinct from `nil` and must be separately checked for (but treated in the same way). Tests and inline documentation have been updated to reflect this new understanding. * Add Content-Type for outgoing Wireserver POSTs Because the Body of the request was replaced, Go also has no idea what the content type should be. It can't read from the reader to perform the detection, so this just sets it to JSON manually. As mentioned in the comments, this is a good idea anyway since we're being explicit rather than relying on heuristic methods to do the right thing.
In cases where clients using a WireserverTransport (namely the NMAgent one) do not wish to provide a body, one must be provided to satisfy quirks of Wireserver. Initially, an empty Go string was thought to be sufficient, but this is not. Wireserver expects an empty JSON string: specifically the 2-byte sequence "". Furthermore, this logic was only being triggered on cases where a nil body was presented to the WireserverTransport's logic. Given that there are now more linters enforcing the use of `http.NoBody`, this is distinct from `nil` and must be separately checked for (but treated in the same way). Tests and inline documentation have been updated to reflect this new understanding. * Add Content-Type for outgoing Wireserver POSTs Because the Body of the request was replaced, Go also has no idea what the content type should be. It can't read from the reader to perform the detection, so this just sets it to JSON manually. As mentioned in the comments, this is a good idea anyway since we're being explicit rather than relying on heuristic methods to do the right thing.
In cases where clients using a WireserverTransport (namely the NMAgent one) do not wish to provide a body, one must be provided to satisfy quirks of Wireserver. Initially, an empty Go string was thought to be sufficient, but this is not. Wireserver expects an empty JSON string: specifically the 2-byte sequence "". Furthermore, this logic was only being triggered on cases where a nil body was presented to the WireserverTransport's logic. Given that there are now more linters enforcing the use of `http.NoBody`, this is distinct from `nil` and must be separately checked for (but treated in the same way). Tests and inline documentation have been updated to reflect this new understanding. * Add Content-Type for outgoing Wireserver POSTs Because the Body of the request was replaced, Go also has no idea what the content type should be. It can't read from the reader to perform the detection, so this just sets it to JSON manually. As mentioned in the comments, this is a good idea anyway since we're being explicit rather than relying on heuristic methods to do the right thing.
In cases where clients using a WireserverTransport (namely the NMAgent one) do not wish to provide a body, one must be provided to satisfy quirks of Wireserver. Initially, an empty Go string was thought to be sufficient, but this is not. Wireserver expects an empty JSON string: specifically the 2-byte sequence "". Furthermore, this logic was only being triggered on cases where a nil body was presented to the WireserverTransport's logic. Given that there are now more linters enforcing the use of `http.NoBody`, this is distinct from `nil` and must be separately checked for (but treated in the same way). Tests and inline documentation have been updated to reflect this new understanding. * Add Content-Type for outgoing Wireserver POSTs Because the Body of the request was replaced, Go also has no idea what the content type should be. It can't read from the reader to perform the detection, so this just sets it to JSON manually. As mentioned in the comments, this is a good idea anyway since we're being explicit rather than relying on heuristic methods to do the right thing.
In cases where clients using a WireserverTransport (namely the NMAgent one) do not wish to provide a body, one must be provided to satisfy quirks of Wireserver. Initially, an empty Go string was thought to be sufficient, but this is not. Wireserver expects an empty JSON string: specifically the 2-byte sequence "".
Furthermore, this logic was only being triggered on cases where a nil body was presented to the WireserverTransport's logic. Given that there are now more linters enforcing the use of
http.NoBody, this is distinct fromniland must be separately checked for (but treated in the same way).Tests and inline documentation have been updated to reflect this new understanding.
Notes: