-
Notifications
You must be signed in to change notification settings - Fork 100
Fix/refresh unused keys #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6c02a7b
5cccfde
7a8fc0e
b5d24f7
38be8af
28992b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,7 @@ private static void makeSporkDefinition(SporkId sporkId, long defaultValue) { | |
| @GuardedBy("lock") private final HashMap<SporkId, Long> mapSporksCachedValues; | ||
| @GuardedBy("lock") private final HashSet<KeyId> setSporkPubKeyIds = new HashSet<>(); | ||
|
|
||
| private PeerGroup peerGroup; | ||
| private AbstractBlockChain blockChain; | ||
| private MasternodeSync masternodeSync; | ||
| private final Context context; | ||
|
|
@@ -91,6 +92,7 @@ public SporkManager(Context context) | |
| public void setBlockChain(AbstractBlockChain blockChain, @Nullable PeerGroup peerGroup, MasternodeSync masternodeSync) { | ||
| this.blockChain = blockChain; | ||
| this.masternodeSync = masternodeSync; | ||
| this.peerGroup = peerGroup; | ||
| if (peerGroup != null) { | ||
| peerGroup.addConnectedEventListener(peerConnectedEventListener); | ||
| peerGroup.addPreMessageReceivedEventListener(SAME_THREAD, preMessageReceivedEventListener); | ||
|
|
@@ -102,18 +104,25 @@ public void clear() { | |
| mapSporksByHash.clear(); | ||
| } | ||
|
|
||
| public void close(PeerGroup peerGroup) { | ||
| if (peerGroup != null) { | ||
| peerGroup.removeConnectedEventListener(peerConnectedEventListener); | ||
| peerGroup.removePreMessageReceivedEventListener(preMessageReceivedEventListener); | ||
| } | ||
| public void close() { | ||
| // No per-peer listener removal needed here: | ||
| // - preMessageReceivedEventListener is removed from each peer by PeerGroup.handlePeerDeath() | ||
| // - peerConnectedEventListener left on a disconnecting peer is harmless (it will never fire) | ||
| // Calling removeConnectedEventListener/removePreMessageReceivedEventListener would iterate | ||
| // getConnectedPeers() under the PeerGroup lock, which can deadlock during shutdown when | ||
| // another PeerGroup thread holds that lock while blocked on SPVBlockStore I/O. | ||
| peerGroup = null; | ||
| blockChain = null; | ||
| masternodeSync = null; | ||
|
Comment on lines
+107
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Detach the Skipping 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| void processSpork(Peer from, SporkMessage spork) { | ||
| // if (context.isLiteMode() && !context.allowInstantXinLiteMode()) { | ||
| // return; //disable all darksend/masternode related functionality | ||
| // } | ||
|
|
||
| if (blockChain == null) return; // closed during shutdown | ||
|
|
||
| Sha256Hash hash = spork.getHash(); | ||
| String logMessage = String.format("SPORK -- hash: %s id: %d (%s) value: %10d bestHeight: %d peer=%s:%d", | ||
| hash, spork.getSporkId().value, String.format("%1$35s", spork.getSporkId().name()), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1715,9 +1715,9 @@ public void run() { | |
|
|
||
| @Override | ||
| public void close() { | ||
| if (peerGroup != null) { | ||
| peerGroup.removeGetDataEventListener(getDataEventListener); | ||
| peerGroup.removePreMessageReceivedEventListener(preMessageReceivedEventListener); | ||
| } | ||
| // All peerGroup.remove*EventListener calls skipped: handlePeerDeath() removes per-peer listeners | ||
| // when peers disconnect. Calling these methods acquires the PeerGroup lock via getConnectedPeers(), | ||
| // risking shutdown deadlock. | ||
| peerGroup = null; | ||
|
Comment on lines
+1718
to
+1721
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Lines 1718-1721 only null the local 💡 Proposed fix `@Override`
public void close() {
- // All peerGroup.remove*EventListener calls skipped: handlePeerDeath() removes per-peer listeners
- // when peers disconnect. Calling these methods acquires the PeerGroup lock via getConnectedPeers(),
- // risking shutdown deadlock.
- peerGroup = null;
+ PeerGroup pg = peerGroup;
+ peerGroup = null;
+ if (pg != null && !pg.isRunning()) {
+ pg.removeGetDataEventListener(getDataEventListener);
+ pg.removePreMessageReceivedEventListener(preMessageReceivedEventListener);
+ }
}🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close()is leaving a PeerGroup-wide tracker registered.The listeners added in Lines 138-142 are attached to
PeerGroup, not to individual peers, so the per-peer shutdown reasoning used elsewhere does not apply here.close()only nullspeerGroup, which leavesdownloadProgressTrackerregistered on the old group and able to keep receiving callbacks after shutdown; callingsetPeerGroup()again would also register an additional tracker. This needs explicit detach/replace handling around the stored tracker.🤖 Prompt for AI Agents