Skip to content

Conversation

@timraymond
Copy link
Member

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.

Notes:

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
rbtr previously approved these changes Dec 16, 2022
Copy link
Collaborator

@rbtr rbtr left a 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)
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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.

@smittal22
Copy link
Contributor

This fix works for us. Have tested by building a CNS executable and joinNetwork calls do not fail anymore.

@ashvindeodhar
Copy link
Member

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.
Bypassing the windows test check which has been failing for past few days. This is a contained change w/o which the master will be in a broken state.

@ashvindeodhar ashvindeodhar merged commit 53fb510 into Azure:master Dec 16, 2022
@timraymond timraymond deleted the traymond/fix-wireserver-no-body branch January 3, 2023 18:53
rjdenney pushed a commit to rjdenney/azure-container-networking that referenced this pull request Jan 19, 2023
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.
smittal22 pushed a commit to smittal22/azure-container-networking that referenced this pull request Jan 26, 2023
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.
smittal22 pushed a commit to smittal22/azure-container-networking that referenced this pull request Jan 30, 2023
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.
smittal22 pushed a commit to smittal22/azure-container-networking that referenced this pull request Feb 3, 2023
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.
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.

5 participants