-
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
Changes from 1 commit
c1adfdd
20558cb
b15db89
f6c1bae
e874fab
557aa9f
4588c08
390d427
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,7 @@ public void setAuthority(String authority) { | |
|
||
@Override | ||
public Attributes getAttributes() { | ||
return Attributes.EMPTY; | ||
return transportState().getAttributes(); | ||
} | ||
|
||
class Sink implements AbstractClientStream.Sink { | ||
|
@@ -318,6 +318,12 @@ public void transportDataReceived(okio.Buffer frame, boolean endOfStream) { | |
super.transportDataReceived(new OkHttpReadableBuffer(frame), endOfStream); | ||
} | ||
|
||
public Attributes getAttributes() { | ||
synchronized (lock) { | ||
return transport.getAttributes(); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can get the attributes and save it as a field at There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
@GuardedBy("lock") | ||
private void onEndOfStream() { | ||
if (!framer().isClosed()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
import com.squareup.okhttp.internal.http.StatusLine; | ||
import io.grpc.Attributes; | ||
import io.grpc.CallOptions; | ||
import io.grpc.Grpc; | ||
import io.grpc.Metadata; | ||
import io.grpc.MethodDescriptor; | ||
import io.grpc.MethodDescriptor.MethodType; | ||
|
@@ -149,6 +150,7 @@ private static Map<ErrorCode, Status> buildErrorCodeToStatusMap() { | |
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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
/** | ||
* Indicates the transport is in go-away state: no new streams will be processed, but existing | ||
* streams may continue. | ||
|
@@ -485,6 +487,13 @@ sslSocketFactory, hostnameVerifier, sock, getOverridenHost(), getOverridenPort() | |
startPendingStreams(); | ||
} | ||
|
||
// TODO(zhangkun83): fill channel security attributes | ||
// The return value of OkHttpTlsUpgrader.upgrade is an SSLSocket that has this info | ||
attributes = Attributes | ||
.newBuilder() | ||
.set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, socket.getRemoteSocketAddress()) | ||
.build(); | ||
|
||
rawFrameWriter = variant.newWriter(sink, true); | ||
frameWriter.becomeConnected(rawFrameWriter, socket); | ||
|
||
|
@@ -675,8 +684,7 @@ public void shutdownNow(Status reason) { | |
|
||
@Override | ||
public Attributes getAttributes() { | ||
// TODO(zhangkun83): fill channel security attributes | ||
return Attributes.EMPTY; | ||
return 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.
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 thetransport
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 byOkHttpClientStream
constructor which in turn is invoked byOkHttpClientTransport.newStream()
. ThenewStream()
method on real transport won't be called until the real transport is ready (AfteronTransportReady()
called).