To reproduce: #22559 (comment) (general I2P setup, in+out) #22559 (comment) (multiple in, multiple out)
I’ve observed my node keeping multiple connections to the same peer in various ways, due to long I2P connection negotiation times, as it’s not uncommon to take 10 to 20 seconds to connect to a peer. If additional connections are made during negotiation with the same peer, all connections remain open.
The bug should occur on any network. This is an I2P only node, which I’m sure increases the chances of this bug happening because my peers.dat is tiny. Note that I do not have any addnode= in my config or anything like that.
1 inbound + 1 outbound:
I connected to a peer. 18 seconds later, it connected to me. These connections persisted for over 12 hours. Both peers are running on a very recent 22.99.0 master branch.
2 inbound or 2 inbound: (2 can be any number with the right timing)
A node connected to me twice around the same time. These connections persisted for over 12 hours. This peer was running the 22.0.0 release.
getpeerinfo data for 1 inbound + 1 outbound peers:
  0  {
  1    "id": 680,
  2    "addr": "jz3s4eurm5vzjresf4mwo7oni4bk36daolwxh4iqtewakylgkxmq.b32.i2p:0",
  3    "addrbind": "bitcornrd36coazsbzsz4pdebyzvaplmsalq4kpoljmn6cg6x5zq.b32.i2p:0",
  4    "network": "i2p",
  5    "services": "0000000000000409",
  6    "servicesnames": [
  7      "NETWORK",
  8      "WITNESS",
  9      "NETWORK_LIMITED"
 10    ],
 11    "relaytxes": true,
 12    "lastsend": 1627290126,
 13    "lastrecv": 1627290124,
 14    "last_transaction": 1627290120,
 15    "last_block": 0,
 16    "bytessent": 3930317,
 17    "bytesrecv": 13011805,
 18    "conntime": 1627229534,
 19    "timeoffset": -2,
 20    "pingtime": 3.264304,
 21    "minping": 0.719468,
 22    "version": 70016,
 23    "subver": "/Satoshi:22.99.0(@dunxen)/",
 24    "inbound": false,
 25    "bip152_hb_to": false,
 26    "bip152_hb_from": false,
 27    "startingheight": 692610,
 28    "synced_headers": 692727,
 29    "synced_blocks": 692727,
 30    "inflight": [
 31    ],
 32    "addr_processed": 7049,
 33    "addr_rate_limited": 1244,
 34    "permissions": [
 35    ],
 36    "minfeefilter": 0.00001000,
 37    "bytessent_per_msg": {
 38      "addrv2": 121698,
 39      "feefilter": 32,
 40      "getaddr": 24,
 41      "getdata": 442191,
 42      "getheaders": 1053,
 43      "headers": 8480,
 44      "inv": 3307633,
 45      "notfound": 316,
 46      "ping": 16128,
 47      "pong": 16128,
 48      "sendaddrv2": 24,
 49      "sendcmpct": 66,
 50      "sendheaders": 24,
 51      "tx": 16345,
 52      "verack": 24,
 53      "version": 127,
 54      "wtxidrelay": 24
 55    },
 56    "bytesrecv_per_msg": {
 57      "addrv2": 167167,
 58      "feefilter": 32,
 59      "getdata": 2090,
 60      "getheaders": 1053,
 61      "headers": 12190,
 62      "inv": 3572569,
 63      "notfound": 122,
 64      "ping": 16128,
 65      "pong": 16128,
 66      "sendaddrv2": 24,
 67      "sendcmpct": 66,
 68      "sendheaders": 24,
 69      "tx": 9208916,
 70      "verack": 24,
 71      "version": 136,
 72      "wtxidrelay": 24
 73    },
 74    "connection_type": "outbound-full-relay"
 75  },
 76  {
 77    "id": 682,
 78    "addr": "jz3s4eurm5vzjresf4mwo7oni4bk36daolwxh4iqtewakylgkxmq.b32.i2p:0",
 79    "addrbind": "bitcornrd36coazsbzsz4pdebyzvaplmsalq4kpoljmn6cg6x5zq.b32.i2p:0",
 80    "network": "i2p",
 81    "services": "0000000000000409",
 82    "servicesnames": [
 83      "NETWORK",
 84      "WITNESS",
 85      "NETWORK_LIMITED"
 86    ],
 87    "relaytxes": true,
 88    "lastsend": 1627290124,
 89    "lastrecv": 1627290123,
 90    "last_transaction": 1627290013,
 91    "last_block": 0,
 92    "bytessent": 1585430,
 93    "bytesrecv": 7794448,
 94    "conntime": 1627229552,
 95    "timeoffset": -13,
 96    "pingtime": 1.396263,
 97    "minping": 0.759804,
 98    "version": 70016,
 99    "subver": "/Satoshi:22.99.0(@dunxen)/",
100    "inbound": true,
101    "bip152_hb_to": false,
102    "bip152_hb_from": false,
103    "startingheight": 692610,
104    "synced_headers": 692727,
105    "synced_blocks": 692727,
106    "inflight": [
107    ],
108    "addr_processed": 6055,
109    "addr_rate_limited": 1188,
110    "permissions": [
111    ],
112    "minfeefilter": 0.00001000,
113    "bytessent_per_msg": {
114      "addrv2": 124133,
115      "feefilter": 32,
116      "getdata": 90391,
117      "getheaders": 1053,
118      "headers": 8455,
119      "inv": 1201793,
120      "ping": 16160,
121      "pong": 16160,
122      "sendaddrv2": 24,
123      "sendcmpct": 66,
124      "sendheaders": 24,
125      "tx": 126964,
126      "verack": 24,
127      "version": 127,
128      "wtxidrelay": 24
129    },
130    "bytesrecv_per_msg": {
131      "addrv2": 145913,
132      "cmpctblock": 2422,
133      "feefilter": 32,
134      "getaddr": 24,
135      "getdata": 14266,
136      "getheaders": 1053,
137      "headers": 12084,
138      "inv": 5364780,
139      "notfound": 61,
140      "ping": 16160,
141      "pong": 16160,
142      "sendaddrv2": 24,
143      "sendcmpct": 66,
144      "sendheaders": 24,
145      "tx": 2221195,
146      "verack": 24,
147      "version": 136,
148      "wtxidrelay": 24
149    },
150    "connection_type": "inbound"
151  }
getpeerinfo data for 2 inbound peers:
  0 {
  1    "id": 1326,
  2    "addr": "acgncqkgqekcxaagpes6ubfiuhg54ijklwcupbnitte5svh3a3bq.b32.i2p:0",
  3    "addrbind": "bitcornrd36coazsbzsz4pdebyzvaplmsalq4kpoljmn6cg6x5zq.b32.i2p:0",
  4    "network": "i2p",
  5    "services": "0000000000000409",
  6    "servicesnames": [
  7      "NETWORK",
  8      "WITNESS",
  9      "NETWORK_LIMITED"
 10    ],
 11    "relaytxes": true,
 12    "lastsend": 1629449575,
 13    "lastrecv": 1629449571,
 14    "last_transaction": 1629449402,
 15    "last_block": 0,
 16    "bytessent": 4675731,
 17    "bytesrecv": 5393457,
 18    "conntime": 1629383715,
 19    "timeoffset": -3,
 20    "pingtime": 2.009341,
 21    "minping": 0.5858950000000001,
 22    "version": 70016,
 23    "subver": "/Satoshi:22.0.0(MN@ca)/",
 24    "inbound": true,
 25    "bip152_hb_to": false,
 26    "bip152_hb_from": false,
 27    "startingheight": 696531,
 28    "synced_headers": 696664,
 29    "synced_blocks": 696664,
 30    "inflight": [
 31    ],
 32    "addr_relay_enabled": true,
 33    "addr_processed": 6062,
 34    "addr_rate_limited": 0,
 35    "permissions": [
 36    ],
 37    "minfeefilter": 0.00001000,
 38    "bytessent_per_msg": {
 39      "addrv2": 149637,
 40      "cmpctblock": 5710,
 41      "feefilter": 32,
 42      "getdata": 2941,
 43      "getheaders": 1053,
 44      "headers": 9752,
 45      "inv": 3847162,
 46      "notfound": 3173,
 47      "ping": 17568,
 48      "pong": 17312,
 49      "sendaddrv2": 24,
 50      "sendcmpct": 66,
 51      "sendheaders": 24,
 52      "tx": 621102,
 53      "verack": 24,
 54      "version": 127,
 55      "wtxidrelay": 24
 56    },
 57    "bytesrecv_per_msg": {
 58      "addrv2": 130686,
 59      "feefilter": 32,
 60      "getaddr": 24,
 61      "getdata": 51317,
 62      "getheaders": 1053,
 63      "headers": 10519,
 64      "inv": 5142494,
 65      "ping": 17312,
 66      "pong": 17568,
 67      "sendaddrv2": 24,
 68      "sendcmpct": 66,
 69      "sendheaders": 24,
 70      "tx": 22157,
 71      "verack": 24,
 72      "version": 133,
 73      "wtxidrelay": 24
 74    },
 75    "connection_type": "inbound"
 76  },
 77  {
 78    "id": 1327,
 79    "addr": "acgncqkgqekcxaagpes6ubfiuhg54ijklwcupbnitte5svh3a3bq.b32.i2p:0",
 80    "addrbind": "bitcornrd36coazsbzsz4pdebyzvaplmsalq4kpoljmn6cg6x5zq.b32.i2p:0",
 81    "network": "i2p",
 82    "services": "0000000000000409",
 83    "servicesnames": [
 84      "NETWORK",
 85      "WITNESS",
 86      "NETWORK_LIMITED"
 87    ],
 88    "relaytxes": true,
 89    "lastsend": 1629449578,
 90    "lastrecv": 1629449580,
 91    "last_transaction": 1629448430,
 92    "last_block": 0,
 93    "bytessent": 4869327,
 94    "bytesrecv": 5433036,
 95    "conntime": 1629383742,
 96    "timeoffset": -21,
 97    "pingtime": 1.979714,
 98    "minping": 0.69269,
 99    "version": 70016,
100    "subver": "/Satoshi:22.0.0(MN@ca)/",
101    "inbound": true,
102    "bip152_hb_to": false,
103    "bip152_hb_from": false,
104    "startingheight": 696531,
105    "synced_headers": 696664,
106    "synced_blocks": 696664,
107    "inflight": [
108    ],
109    "addr_relay_enabled": true,
110    "addr_processed": 6188,
111    "addr_rate_limited": 0,
112    "permissions": [
113    ],
114    "minfeefilter": 0.00001000,
115    "bytessent_per_msg": {
116      "addrv2": 148858,
117      "feefilter": 32,
118      "getdata": 1932,
119      "getheaders": 1053,
120      "headers": 9858,
121      "inv": 3872869,
122      "notfound": 2259,
123      "ping": 17568,
124      "pong": 17312,
125      "sendaddrv2": 24,
126      "sendcmpct": 66,
127      "sendheaders": 24,
128      "tx": 797297,
129      "verack": 24,
130      "version": 127,
131      "wtxidrelay": 24
132    },
133    "bytesrecv_per_msg": {
134      "addrv2": 133478,
135      "feefilter": 32,
136      "getaddr": 24,
137      "getdata": 68654,
138      "getheaders": 1053,
139      "headers": 10625,
140      "inv": 5171958,
141      "ping": 17312,
142      "pong": 17568,
143      "sendaddrv2": 24,
144      "sendcmpct": 66,
145      "sendheaders": 24,
146      "tx": 12037,
147      "verack": 24,
148      "version": 133,
149      "wtxidrelay": 24
150    },
151    "connection_type": "inbound"
152  }