-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
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.
I think I can loadbalance this PR over to @dapengzhang0 |
@@ -318,6 +318,12 @@ public void transportDataReceived(okio.Buffer frame, boolean endOfStream) { | |||
super.transportDataReceived(new OkHttpReadableBuffer(frame), endOfStream); | |||
} | |||
|
|||
public Attributes getAttributes() { | |||
synchronized (lock) { |
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.
lock is not needed if attributes is volatile
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.
This lock is required to make the @GuardedBy
around the transport
happy.
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.
Then maybe you can cache the attribute in TransportState constructor.
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.
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.
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.
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; |
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.
- maybe volatile
- maybe init with EMPTY
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.
You're right, this needs to be volatile and set while holding the lock.
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.
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.
|
@@ -467,6 +471,10 @@ public void close() {} | |||
sock.setTcpNoDelay(true); | |||
source = Okio.buffer(Okio.source(sock)); | |||
sink = Okio.buffer(Okio.sink(sock)); | |||
attrs = Attributes |
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.
You can set attributes
field directly here. Otherwise LGTM.
@SuppressWarnings("GuardedBy") | ||
public Attributes getAttributes() { | ||
return transport.getAttributes(); | ||
} |
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.
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.
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.
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
@carl-mastrangelo do you have any remaining concerns with this PR? |
@carl-mastrangelo ping |
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.
LGTM
verify(listener, timeout(100)).transportReady(); | ||
} | ||
|
||
|
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: extra space
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.