Skip to content

Conversation

@fishy
Copy link
Member

@fishy fishy commented Dec 17, 2020

Client: go

Define TConfiguration following the spec, and also move the following
configurations scattered around different TTransport/TProtocol into it:

  • connect and socket timeouts for TSocket and TSSLSocket
  • tls config for TSSLSocket
  • max frame size for TFramedTransport
  • strict read and strict write for TBinaryProtocol
  • proto id for THeaderTransport

Also add TConfiguration support for the following and their factories:

  • THeaderTransport and THeaderProtocol
  • TBinaryProtocol
  • TCompactProtocol
  • TFramedTransport
  • TSocket
  • TSSLSocket

Also define TConfigurationSetter interface for easier TConfiguration
propagation between wrapped TTransports/TProtocols , and add
implementations to the following for propagation
(they don't use anything from TConfiguration themselves):

  • StreamTransport
  • TBufferedTransport
  • TDebugProtocol
  • TJSONProtocol
  • TSimpleJSONProtocol
  • TZlibTransport

TConfigurationSetter are not implemented by the factories of the
"propagation only" TTransports/TProtocols, if they have a factory. For
those use cases, TTransportFactoryConf and TProtocolFactoryConf are
provided to wrap a factory with the ability to propagate TConfiguration.

Also add simple sanity check for TBinaryProtocol and TCompactProtocol's
ReadString and ReadBinary functions. Currently it only report error if
the header length is larger than MaxMessageSize configured in
TConfiguration, for simplicity.

@fishy fishy requested review from Jens-G and dcelasun December 17, 2020 01:19

// NewTHeaderProtocolFactoryWithProtocolID creates a factory for THeader with
// given protocol ID.
func NewTHeaderProtocolFactoryWithProtocolID(protoID THeaderProtocolID) (TProtocolFactory, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

note that this is a breaking change from a previous version on master branch. however it is not a breaking change from 0.13.0.

@fishy fishy force-pushed the go-tconfiguration branch from c047f4e to 173ea94 Compare December 17, 2020 01:23
@dcelasun
Copy link
Member

LGTM from a quick read but I won't be able to test until the new year.

Copy link
Member

@Jens-G Jens-G left a comment

Choose a reason for hiding this comment

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

Good work!

LGTM overall. I only did a code review, did not run any tests on it. Only minor/cosmetic issues found.

}
size := binary.BigEndian.Uint32(buf)
if size < 0 || size > p.maxLength {
if size < 0 || size > uint32(p.cfg.GetMaxFrameSize()) {
Copy link
Member

Choose a reason for hiding this comment

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

The code was there before but I really wonder when size will become negative on an uint32?

Copy link
Member Author

Choose a reason for hiding this comment

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

Before p.maxLength actually has the type of uint32 instead of int32.

To become negative when converting to int32 the uint32 value needs to be at least 2GB (MaxInt32 is 1<<31-1). I'm not sure how much do we really care about that use case. If we do care about it I can change the types of MaxMessageSize and MaxFrameSize both from int32 to uint32.

Copy link
Member

Choose a reason for hiding this comment

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

I very much doubt this is a legitimate possibility, int32 seems fine to me.

return p.protocol.Skip(ctx, fieldType)
}

// SetTConfiguration implemtns TConfigurationSetter.
Copy link
Member

Choose a reason for hiding this comment

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

... implements ... (there is more than one instance of this typo)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Fixed.

@fishy fishy force-pushed the go-tconfiguration branch from 173ea94 to 1dbf3ac Compare December 23, 2020 20:04
@fishy
Copy link
Member Author

fishy commented Dec 23, 2020

I moved timeouts from TSocket/TSSLSocket to TConfiguration, and added propagation support to more TTransport/TProtocol implementations, and also updated the commit message/PR description. I believe now TMemoryBuffer is the only one not supporting either TConfiguration or TConfigurationSetter, as it doesn't need any configurations itself and also it's always the terminal TTransport that it has nothing underneath to propagate into.

Please take another look.

@fishy fishy force-pushed the go-tconfiguration branch 4 times, most recently from 2e93211 to 36ae85f Compare December 28, 2020 18:23
Copy link
Member

@dcelasun dcelasun left a comment

Choose a reason for hiding this comment

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

Finally had a chance to play around with this. I've tested framed transport and binary protocol, works as expected.

Thanks for working on this :)

}
size := binary.BigEndian.Uint32(buf)
if size < 0 || size > p.maxLength {
if size < 0 || size > uint32(p.cfg.GetMaxFrameSize()) {
Copy link
Member

Choose a reason for hiding this comment

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

I very much doubt this is a legitimate possibility, int32 seems fine to me.

// NewTHeaderProtocol creates a new THeaderProtocol from the underlying
// transport with default protocol ID.
// NewTHeaderProtocolConf creates a new THeaderProtocol from the underlying
// transport with gien TConfiguration.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// transport with gien TConfiguration.
// transport with given TConfiguration.

@fishy fishy force-pushed the go-tconfiguration branch 2 times, most recently from baad75e to af0664c Compare January 17, 2021 19:07
Client: go

Define TConfiguration following the spec, and also move the following
configurations scattered around different TTransport/TProtocol into it:

- connect and socket timeouts for TSocket and TSSLSocket
- tls config for TSSLSocket
- max frame size for TFramedTransport
- strict read and strict write for TBinaryProtocol
- proto id for THeaderTransport

Also add TConfiguration support for the following and their factories:

- THeaderTransport and THeaderProtocol
- TBinaryProtocol
- TCompactProtocol
- TFramedTransport
- TSocket
- TSSLSocket

Also define TConfigurationSetter interface for easier TConfiguration
propagation between wrapped TTransports/TProtocols , and add
implementations to the following for propagation
(they don't use anything from TConfiguration themselves):

- StreamTransport
- TBufferedTransport
- TDebugProtocol
- TJSONProtocol
- TSimpleJSONProtocol
- TZlibTransport

TConfigurationSetter are not implemented by the factories of the
"propagation only" TTransports/TProtocols, if they have a factory. For
those use cases, TTransportFactoryConf and TProtocolFactoryConf are
provided to wrap a factory with the ability to propagate TConfiguration.

Also add simple sanity check for TBinaryProtocol and TCompactProtocol's
ReadString and ReadBinary functions. Currently it only report error if
the header length is larger than MaxMessageSize configured in
TConfiguration, for simplicity.
@fishy fishy force-pushed the go-tconfiguration branch from af0664c to fd53d7a Compare January 17, 2021 20:24
@fishy fishy merged commit c4d1c0d into apache:master Jan 17, 2021
@fishy fishy deleted the go-tconfiguration branch January 17, 2021 20:24
fishy added a commit that referenced this pull request Jan 22, 2021
Client: go

This fixes a bug introduced in
#2296, that we mixed the preferred
proto id and the detected proto id, which was a bad idea.

This change separates them, so when we propagate TConfiguration, we only
change the preferred one, which will only be used for new connections,
and leave the detected one from existing connections untouched.
fishy added a commit to fishy/thrift that referenced this pull request Jan 22, 2021
Client: go

This fixes a bug introduced in
apache#2296, that we mixed the preferred
proto id and the detected proto id, which was a bad idea.

This change separates them, so when we propagate TConfiguration, we only
change the preferred one, which will only be used for new connections,
and leave the detected one from existing connections untouched.
fishy added a commit to fishy/thrift that referenced this pull request Jan 23, 2021
Client: go

This fixes a bug introduced in
apache#2296, that we mixed the preferred
proto id and the detected proto id, which was a bad idea.

This change separates them, so when we propagate TConfiguration, we only
change the preferred one, which will only be used for new connections,
and leave the detected one from existing connections untouched.

Also add a test for it.
fishy added a commit that referenced this pull request Jan 23, 2021
Client: go

This fixes a bug introduced in
#2296, that we mixed the preferred
proto id and the detected proto id, which was a bad idea.

This change separates them, so when we propagate TConfiguration, we only
change the preferred one, which will only be used for new connections,
and leave the detected one from existing connections untouched.

Also add a test for it.
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.

3 participants