Skip to content

Commit dcc0d78

Browse files
echistyakovmeta-codesync[bot]
authored andcommitted
Protect against nil in Thrift WithConnContext option
Summary: Handle `nil` correctly. Needed downstream. Reviewed By: podtserkovskiy Differential Revision: D95653367 fbshipit-source-id: 47aeaaf39a52d76a43f201a3464335c215afc381
1 parent 23c34ab commit dcc0d78

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

third-party/thrift/src/thrift/lib/go/thrift/server_options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func WithNumWorkers(num int) ServerOption {
8888
// that specifies a function that modifies the context passed to procedures per connection.
8989
func WithConnContext(connContext ConnContextFunc) ServerOption {
9090
return func(config *serverConfig) {
91+
if connContext == nil {
92+
return
93+
}
9194
config.connContext = func(ctx context.Context, conn net.Conn) context.Context {
9295
ctx = WithConnInfo(ctx, conn)
9396
return connContext(ctx, conn)

third-party/thrift/src/thrift/lib/go/thrift/server_options_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func TestWithConnContext(t *testing.T) {
6161
require.NotNil(t, defaultConfig.connContext)
6262
defaultConfig.connContext(context.TODO(), dummyConn)
6363

64+
nilConfig := newServerConfig(WithConnContext(nil))
65+
require.NotNil(t, nilConfig.connContext)
66+
nilConfig.connContext(context.TODO(), dummyConn)
67+
6468
invoked := false
6569
customConnContextFn := func(ctx context.Context, conn net.Conn) context.Context { invoked = true; return ctx }
6670
customConfig := newServerConfig(WithConnContext(customConnContextFn))

0 commit comments

Comments
 (0)