Skip to content

netty,okhttp,testing: always set TRANSPORT_ATTR_REMOTE_ADDR #4217

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

Merged
merged 8 commits into from
Mar 23, 2018

Conversation

zpencer
Copy link
Contributor

@zpencer zpencer commented Mar 14, 2018

Always set the remote address, no reason why this should be a TLS-only
feature. This is needed for channelz, and is especially useful in unit
tests where we are using plaintext.

Always set the remote address, no reason why this should be a TLS-only
feature. This is needed for channelz, and is especially useful in unit
tests where we are using plaintext.
@zpencer
Copy link
Contributor Author

zpencer commented Mar 14, 2018

I think I can loadbalance this PR over to @dapengzhang0

@zpencer zpencer requested review from dapengzhang0 and removed request for carl-mastrangelo March 14, 2018 17:32
@dapengzhang0
Copy link
Member

cc @maseev #4118

@@ -318,6 +318,12 @@ public void transportDataReceived(okio.Buffer frame, boolean endOfStream) {
super.transportDataReceived(new OkHttpReadableBuffer(frame), endOfStream);
}

public Attributes getAttributes() {
synchronized (lock) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock is not needed if attributes is volatile

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lock is required to make the @GuardedBy around the transport happy.

Copy link
Member

@dapengzhang0 dapengzhang0 Mar 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe you can cache the attribute in TransportState constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time TransportState is constructed, start may not have been called yet. Copying the attributes to a volatile at start or stream allocated will work, but adds more things for us to keep track of. I opted to suppress the warning, PTAL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransportState constructor is invoked by OkHttpClientStream constructor which in turn is invoked by OkHttpClientTransport.newStream(). The newStream() method on real transport won't be called until the real transport is ready (After onTransportReady() called).

  // InternalSubchannel.java
  /**
   * The transport for new outgoing requests. 'lock' must be held when assigning to it. Non-null
   * only in READY state.
   */
  @Nullable
  private volatile ManagedClientTransport activeTransport;

@@ -149,6 +150,7 @@
private final int maxMessageSize;
private int connectionUnacknowledgedBytesRead;
private ClientFrameHandler clientFrameHandler;
private Attributes attributes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • maybe volatile
  • maybe init with EMPTY

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this needs to be volatile and set while holding the lock.

Copy link
Contributor

@carl-mastrangelo carl-mastrangelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would need to be further convinced this change is correct. How does this not interfere with the SSL or ALTS negotiators? They have to to call the method too.

@zpencer
Copy link
Contributor Author

zpencer commented Mar 15, 2018

BufferUntilProxyTunnelledHandler should have its changes reverted because that one can lead to interference. The two remaining changed negotiators do not interfere with SSL and ALTS because they are plaintext only:

  • BufferUntilChannelActiveHandler used by plainText()
  • BufferingHttp2UpgradeHandler used by plaintextUpgrade()

@@ -467,6 +471,10 @@ public void close() {}
sock.setTcpNoDelay(true);
source = Okio.buffer(Okio.source(sock));
sink = Okio.buffer(Okio.sink(sock));
attrs = Attributes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set attributes field directly here. Otherwise LGTM.

@SuppressWarnings("GuardedBy")
public Attributes getAttributes() {
return transport.getAttributes();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the attributes and save it as a field at TransportState constructor, the transport is guaranteed in READY state when the constructor is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. This required updating some unit tests to ensure streams are not started until the transport is ready.

- copy the attr at construction time
- update unit tests to wait until transport is ready before creating
  streams
@zpencer
Copy link
Contributor Author

zpencer commented Mar 22, 2018

@carl-mastrangelo do you have any remaining concerns with this PR?

@zpencer
Copy link
Contributor Author

zpencer commented Mar 23, 2018

@carl-mastrangelo ping

Copy link
Contributor

@carl-mastrangelo carl-mastrangelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

verify(listener, timeout(100)).transportReady();
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra space

@zpencer zpencer merged commit a5b55bb into grpc:master Mar 23, 2018
@zpencer zpencer deleted the always-set-remoteaddress-attr branch March 26, 2018 16:46
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
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.

3 participants