Fix websocket leaks (#1334)
This commit is contained in:
		
							parent
							
								
									ec6124ca62
								
							
						
					
					
						commit
						d09f7c5427
					
				| @ -69,6 +69,9 @@ export class Relay { | |||||||
| 
 | 
 | ||||||
|     try { |     try { | ||||||
|       return await withTimeout(checkPromise, timeout) |       return await withTimeout(checkPromise, timeout) | ||||||
|  |     } catch (err) { | ||||||
|  |       this.close() | ||||||
|  |       throw err | ||||||
|     } finally { |     } finally { | ||||||
|       clearInterval(interval) |       clearInterval(interval) | ||||||
|     } |     } | ||||||
| @ -187,7 +190,11 @@ export function nostrZapDetails (zap) { | |||||||
| async function publishNostrEvent (signedEvent, relayUrl) { | async function publishNostrEvent (signedEvent, relayUrl) { | ||||||
|   const timeout = 3000 |   const timeout = 3000 | ||||||
|   const relay = await Relay.connect(relayUrl, { timeout }) |   const relay = await Relay.connect(relayUrl, { timeout }) | ||||||
|   await relay.publish(signedEvent, { timeout }) |   try { | ||||||
|  |     await relay.publish(signedEvent, { timeout }) | ||||||
|  |   } finally { | ||||||
|  |     relay.close() | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function crosspost (event, relays = DEFAULT_CROSSPOSTING_RELAYS) { | export async function crosspost (event, relays = DEFAULT_CROSSPOSTING_RELAYS) { | ||||||
|  | |||||||
| @ -54,7 +54,11 @@ export async function nip57 ({ data: { hash }, boss, lnd, models }) { | |||||||
|       relays.map(async r => { |       relays.map(async r => { | ||||||
|         const timeout = 1000 |         const timeout = 1000 | ||||||
|         const relay = await Relay.connect(r, { timeout }) |         const relay = await Relay.connect(r, { timeout }) | ||||||
|         await relay.publish(e, { timeout }) |         try { | ||||||
|  |           await relay.publish(e, { timeout }) | ||||||
|  |         } finally { | ||||||
|  |           relay.close() | ||||||
|  |         } | ||||||
|       }) |       }) | ||||||
|     ) |     ) | ||||||
|   } catch (e) { |   } catch (e) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user