Skip to content

Commit 84c3799

Browse files
authored
rpc: more accurate checking of handler method signatures (#27287)
This changes the RPC server to ignore methods using *context.Context as parameter and *error as return value type. Methods with such types would crash the server when called.
1 parent ae1d90e commit 84c3799

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

rpc/service.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,8 @@ func (c *callback) call(ctx context.Context, method string, args []reflect.Value
214214
return results[0].Interface(), nil
215215
}
216216

217-
// Is t context.Context or *context.Context?
218-
func isContextType(t reflect.Type) bool {
219-
for t.Kind() == reflect.Ptr {
220-
t = t.Elem()
221-
}
222-
return t == contextType
223-
}
224-
225217
// Does t satisfy the error interface?
226218
func isErrorType(t reflect.Type) bool {
227-
for t.Kind() == reflect.Ptr {
228-
t = t.Elem()
229-
}
230219
return t.Implements(errorType)
231220
}
232221

@@ -245,7 +234,7 @@ func isPubSub(methodType reflect.Type) bool {
245234
if methodType.NumIn() < 2 || methodType.NumOut() != 2 {
246235
return false
247236
}
248-
return isContextType(methodType.In(1)) &&
237+
return methodType.In(1) == contextType &&
249238
isSubscriptionType(methodType.Out(0)) &&
250239
isErrorType(methodType.Out(1))
251240
}

0 commit comments

Comments
 (0)