Commit f0efac5 1 parent 337f063 commit f0efac5 Copy full SHA for f0efac5
File tree 1 file changed +21
-8
lines changed
core/network/notifications
1 file changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -184,14 +184,27 @@ namespace kagome::network::notifications {
184
184
if (not peer) {
185
185
return ;
186
186
}
187
- peer.insert_or_assign (PeerOutBackoff{
188
- scheduler_->scheduleWithHandle (
189
- [WEAK_SELF, peer_id] {
190
- WEAK_LOCK (self);
191
- self->onBackoff (peer_id);
192
- },
193
- backoffTime ()),
194
- });
187
+ /*
188
+ there was bug causing double free.
189
+ *peer = PeerOutBackoff
190
+ variant assignment destroys old contained value then inserts new.
191
+ `~PeerOutOpen` calls `YamuxStream::reset`,
192
+ `YamuxStream::reset` cancels pending read,
193
+ read error calls `onError`,
194
+ `onError` calls `backoff`,
195
+ but `peer` still contains half-destructed `PeerOutOpen`,
196
+ and calls `~PeerOutOpen` again,
197
+ causing double free.
198
+ */
199
+ std::exchange (*peer,
200
+ PeerOutBackoff{
201
+ scheduler_->scheduleWithHandle (
202
+ [WEAK_SELF, peer_id] {
203
+ WEAK_LOCK (self);
204
+ self->onBackoff (peer_id);
205
+ },
206
+ backoffTime ()),
207
+ });
195
208
}
196
209
197
210
void Protocol::onBackoff (const PeerId &peer_id) {
You can’t perform that action at this time.
0 commit comments