You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/tendermint/tendermint/libs/log"
  6. tmos "github.com/tendermint/tendermint/libs/os"
  7. rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
  8. rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
  9. )
  10. var routes = map[string]*rpcserver.RPCFunc{
  11. "hello_world": rpcserver.NewRPCFunc(HelloWorld, "name,num", false),
  12. }
  13. func HelloWorld(ctx *rpctypes.Context, name string, num int) (Result, error) {
  14. return Result{fmt.Sprintf("hi %s %d", name, num)}, nil
  15. }
  16. type Result struct {
  17. Result string
  18. }
  19. func main() {
  20. var (
  21. mux = http.NewServeMux()
  22. logger = log.MustNewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo, false)
  23. )
  24. // Stop upon receiving SIGTERM or CTRL-C.
  25. tmos.TrapSignal(logger, func() {})
  26. rpcserver.RegisterRPCFuncs(mux, routes, logger)
  27. config := rpcserver.DefaultConfig()
  28. listener, err := rpcserver.Listen("tcp://127.0.0.1:8008", config)
  29. if err != nil {
  30. tmos.Exit(err.Error())
  31. }
  32. if err = rpcserver.Serve(listener, mux, logger, config); err != nil {
  33. tmos.Exit(err.Error())
  34. }
  35. }