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.

100 lines
2.0 KiB

7 years ago
7 years ago
7 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
  1. package dummy
  2. import (
  3. "net"
  4. cmn "github.com/tendermint/tendermint/libs/common"
  5. p2p "github.com/tendermint/tendermint/p2p"
  6. tmconn "github.com/tendermint/tendermint/p2p/conn"
  7. )
  8. type peer struct {
  9. cmn.BaseService
  10. kv map[string]interface{}
  11. }
  12. var _ p2p.Peer = (*peer)(nil)
  13. // NewPeer creates new dummy peer.
  14. func NewPeer() *peer {
  15. p := &peer{
  16. kv: make(map[string]interface{}),
  17. }
  18. p.BaseService = *cmn.NewBaseService(nil, "peer", p)
  19. return p
  20. }
  21. // FlushStop just calls Stop.
  22. func (p *peer) FlushStop() {
  23. p.Stop()
  24. }
  25. // ID always returns dummy.
  26. func (p *peer) ID() p2p.ID {
  27. return p2p.ID("dummy")
  28. }
  29. // IsOutbound always returns false.
  30. func (p *peer) IsOutbound() bool {
  31. return false
  32. }
  33. // IsPersistent always returns false.
  34. func (p *peer) IsPersistent() bool {
  35. return false
  36. }
  37. // NodeInfo always returns empty node info.
  38. func (p *peer) NodeInfo() p2p.NodeInfo {
  39. return p2p.DefaultNodeInfo{}
  40. }
  41. // RemoteIP always returns localhost.
  42. func (p *peer) RemoteIP() net.IP {
  43. return net.ParseIP("127.0.0.1")
  44. }
  45. // Addr always returns tcp://localhost:8800.
  46. func (p *peer) RemoteAddr() net.Addr {
  47. return &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8800}
  48. }
  49. // CloseConn always returns nil.
  50. func (p *peer) CloseConn() error {
  51. return nil
  52. }
  53. // Status always returns empry connection status.
  54. func (p *peer) Status() tmconn.ConnectionStatus {
  55. return tmconn.ConnectionStatus{}
  56. }
  57. // Send does not do anything and just returns true.
  58. func (p *peer) Send(byte, []byte) bool {
  59. return true
  60. }
  61. // TrySend does not do anything and just returns true.
  62. func (p *peer) TrySend(byte, []byte) bool {
  63. return true
  64. }
  65. // Set records value under key specified in the map.
  66. func (p *peer) Set(key string, value interface{}) {
  67. p.kv[key] = value
  68. }
  69. // Get returns a value associated with the key. Nil is returned if no value
  70. // found.
  71. func (p *peer) Get(key string) interface{} {
  72. if value, ok := p.kv[key]; ok {
  73. return value
  74. }
  75. return nil
  76. }
  77. // OriginalAddr always returns nil.
  78. func (p *peer) OriginalAddr() *p2p.NetAddress {
  79. return nil
  80. }