Skip to content

Commit 785af4a

Browse files
authored
fix: more ethers.js cleanup silencing (#144)
Ref: #55 (comment)
1 parent 86c839f commit 785af4a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/core/synapse/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,27 @@ export function getDefaultStorageContextConfig(overrides: any = {}) {
561561
*/
562562
export async function cleanupProvider(provider: any): Promise<void> {
563563
if (provider && typeof provider.destroy === 'function') {
564+
// Suppress all errors during cleanup
565+
// WebSocket providers can throw async errors from scheduled operations
566+
// (like eth_unsubscribe) after destroy() is called
567+
const errorHandler = () => {
568+
// Silently ignore all cleanup errors
569+
}
570+
571+
// Add error listener to suppress errors from async operations
572+
if (typeof provider.on === 'function') {
573+
provider.on('error', errorHandler)
574+
}
575+
564576
try {
565577
await provider.destroy()
566578
} catch {
567579
// Ignore cleanup errors
568580
}
581+
582+
// Small delay to allow any pending async operations to complete
583+
// This prevents errors from scheduled operations that trigger after destroy()
584+
await new Promise((resolve) => setTimeout(resolve, 100))
569585
}
570586
}
571587

0 commit comments

Comments
 (0)