Mirror: Best-effort discovery of the machine's local network using just Node.js dgram sockets
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Add missing clean up on DHCP discover timeout (#21)

* Clean up socket on timeout

* Wrap socket.close in try-catch just in case

* Add changeset

+14 -4
+5
.changeset/smart-swans-add.md
··· 1 + --- 2 + 'lan-network': patch 3 + --- 4 + 5 + Add missing `socket.close` for DHCP discover on timeout
+9 -4
src/dhcp.ts
··· 53 53 `Received no reply to DHCPDISCOVER in ${DHCP_TIMEOUT}ms` 54 54 ) 55 55 ); 56 + cleanup(); 56 57 }, DHCP_TIMEOUT); 57 58 const socket = createSocket( 58 59 { type: 'udp4', reuseAddr: true }, ··· 65 66 66 67 clearTimeout(timeout); 67 68 resolve(rinfo.address); 69 + cleanup(); 70 + } 71 + ); 72 + function cleanup() { 73 + try { 68 74 socket.close(); 69 75 socket.unref(); 70 - } 71 - ); 76 + } catch {} 77 + } 72 78 socket.on('error', error => { 73 79 clearTimeout(timeout); 74 80 reject(error); 75 - socket.close(); 76 - socket.unref(); 81 + cleanup(); 77 82 }); 78 83 socket.bind(DHCP_CLIENT_PORT, () => { 79 84 socket.setBroadcast(true);